• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How h:message and h:messages work

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic