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