Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How h:message and h:messages work

 
Francesco Stupazzoni
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to set up a jsf page where the user is prompted for an ID and, when the user presses the the button, it shows a new page with user details if ID exist, or a message on the same request page saying "User does not exist".

The relevant page is (replaced brackets with []):

[f:view]
[h:form id="printUser"]
[h:inputText id="myUserID"
value="#{userAvail.userID}" required="true"]
[f:validateLength
minimum="1"][/f:validateLength][/h:inputText]
[h:message showDetail="true" showSummary="true" rendered="true" for="myUserID"][/h:message]
[h:commandButton value="#{bundle.show_user_label}" action="#{userAvail.findUser}" type="submit" title="#{bundle.login_button_label}"][/h:commandButton]


The userAvail.findUser for message generation function is: <br>

FacesContext facesContext = FacesContext.getCurrentInstance();
FacesMessage facesMessage = new FacesMessage(
"User does not exist!");
facesContext.addMessage("myUserID", facesMessage);


My question is: how can I make "User does not exist!" show on the page? Actually, if I use a h:message ... it does not show, if I use a h:messages it is shown.


Thanks
 
Tim De Keyzer
Greenhorn
Posts: 1
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A solution is to create a custom validator method binding, that does the validation. Add a "validation" method to your userBean:



In this method you can add the validation you want. If the user does not exist, you have to set next line in the method:



On your page, add the validator to you

[h:inputText id="myUserID" value="#{userAvail.userID}" required="true" validator="#{userBean.userValidation}]
[f:validateLength minimum="1"][/f:validateLength]
[/h:inputText]

On the component itself, you can override the validation message UIInput#setValidatorMessage(java.lang.String)

component.setValidatorMessage("User does not exist");
 
jaini Naveen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The h:message is for only one component and h:messages is for globule messages
the message looks only one component related messages, but messages takes all the messages in the context.

So if you want the clean rendering information of the messages visit this link
messages, there look at the
AlertMessageRenderer.java portion you will get the detailed view
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic