• 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

h:message rendering

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

Please help me for the following:

In my JSF application, a webpage has h:messages to display errors to the user which occur when any exception has occured. I have coded this by using the addMessage() which is as follows:

/**
* Adds the message matching the key in the application's
* resource bundle, formatted with the parameters (if any),
* the the JSF message queue as a global message.
*/
protected void addMessage(String messageKey, Object param) {
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
String messageBundleName = application.getMessageBundle();
Locale locale = context.getViewRoot().getLocale();
ResourceBundle rb =
ResourceBundle.getBundle(messageBundleName, locale);
String msgPattern = rb.getString(messageKey);
String msg = msgPattern;
if (param != null) {
Object[] params = {param};
msg = MessageFormat.format(msgPattern, params);
}
FacesMessage facesMsg =
new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
context.addMessage(null, facesMsg);
}

On click of a button on the JSP page, the above gets executed. But the rendered page(same as the page with the button) does not show up with the message 1st time. 2nd time onwards, it always shows up. The console out.println shows the correct values that need to be displayed all the time.

Urgent help required!

Thanks,
Ashok
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you provide a sample of your jsf page.. and also the method which calls addMessage method.
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try writing a PhaseListener just to check which lifecycle methods are being processed.

Would you happen to have a ValueChangeListener setup that might be conflicting with the submit? They are known to bypass some lifecycle phases.

 
Ashok Subramaniam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Michael:
Try writing a PhaseListener just to check which lifecycle methods are being processed.

Would you happen to have a ValueChangeListener setup that might be conflicting with the submit? They are known to bypass some lifecycle phases.

 
Ashok Subramaniam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yes, I could not understand the concepts of JSF LifeCycle correctly. The bean which supplied the errors appear after the h:message rendering. Hence the issue. Thanks for trying to help me out.

Ashok.
[ May 09, 2008: Message edited by: Ashok Subramaniam ]
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a similar problem. On first load, I had a page which displays a DataModel and a pager (from Tomahawk library).

If I try to click any of the links/buttons (mapped to JSF actions) during the first load I will just be redirected to the same page. Even if I try to add messages to the FacesContext, nothing is displayed in my page.

But on second try, all the links/buttons worked properly.

As it turned out, I had a property in my managed bean which has a String value = null. This bean property was mapped to a ValueChangeListener method which I had in my page. The select dropdown was trying to change the value from null to -1 (on first load).

I had a renderResponse() call in my ValueChangeListener method which prevented the other phases (like apply request values) to be executed on first try.

The solution was to change the default value of the bean property to -1 (in the constructor or the property declaration). This way the VCL won't be triggered unnecessarily during first load.

You might want to check if the problem you're experiencing is similar to the problem I had.

Hope this helps.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic