I would like to read the backing bean value in JSF and then pass over to JavaScript, may I know how this can be done?
Backing bean sample code:
@ManagedBean(name="enquiry")
@SessionScoped
public class Enquiry {
public boolean noQuery;
/** getter and setter **/
}
In XHTML sample code, I would like pass the backing bean value and then pass into showNoQueryPrompt()
like this:
<h:commandLink onClick="showNoQueryPrompt(#{enquiry.noQuery})">
</h:commandLink>
And then in JavaScript code, I can read the boolean value to determine whether I should prompt or not prompt. Here is the code:
<script ...>
var showNoQueryPrompt(Boolean showPrompt) {
if( showPrompt == "true" ) {
alert('No query');
}
}
</script>
See Question&Answers more detail:os