Reputation: 952
I have a <h:commandButton>
on my page connected with action in my bean. It work just fine, but I wanted to add confirmation message. When I used:
<h:commandButton onclick="confirm('Are you sure?')">
it alco works just fine. But when I try to get string from bean, by making it looks like this:
<h:commandButton onclick="confirm('#{bean.confirmQ}')">
it doesn't display this string. In getter for this string I invoke method to take some info from DB, and I format it then I return it. When I use this approach nothing is shown, not even empty box, and page looks like just refreshing.
Here is code from bean:
private String confirmQ;
public String getConfirmQ() {
WycenioneAuta wa = getWycenioneAuto();
String question = "are you sure \n" + wa.getName + "?";
confirmQ = question;
return confirmQ;
}
public void setConfirmQ(String confirmQ) {
this.confirmQ = confirmQ;
}
Upvotes: 0
Views: 540
Reputation: 367
In complement to ஜன்'s Answer:
At least for Firefox , I should had a return in the Javascript code, otherwise the cancel does not work:
<h:commandButton onclick="return confirm('Are you sure?')" ... />
Upvotes: 0
Reputation:
Escape the line by writing String question = "are you sure \\n" + wa.getName + "?";
If your String variable is confirmQ , then the right EL pointing to that variable is #{bean.confirmQ}
and not #{bean.confirm}
as you've written.
Upvotes: 1