File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How h:message and h:messages work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "How h:message and h:messages work" Watch "How h:message and h:messages work" New topic
Author

How h:message and h:messages work

Francesco Stupazzoni
Greenhorn

Joined: Apr 30, 2008
Posts: 1
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

Joined: Apr 17, 2008
Posts: 1

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

Joined: Jun 10, 2008
Posts: 5
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
 
GeeCON Prague 2014
 
subject: How h:message and h:messages work