Can we add a FacesMessage in the actionListener of an ActionSource?
Hi,
I want to show an error message when the user clicks a button. In the actionListener to the button, I wanted to add a message in case a condition is not satisfied. However everytime, I do not see the error message displayed.
The code in my jsp looks as follows:
<h:commandButton id="_commit"
actionListener="#{myBean.doCommit}"
value="Commit"/>
My bean class has the following code:
public class MyBean{
private boolean valid = false; // Hard coded the value for now.
public void setValid(boolean newValue)
{
this.valid = newValue;
}
public boolean getValid()
{
return valid;
}
public void doCommit(ActionEvent event)
{
if (! valid)
{
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Invalid Selection",
"Invalid Selection");
FacesContext.getCurrentInstance().addMessage(null, message);
} else {
// Commit the data here
}
}
}
I was not able to find a solution for this problem so far. Any suggestions?

