-
1. Re: Unable to render Error Message <h:message> on JSF page
sergeysmirnov Jul 27, 2007 2:14 PM (in response to mail2bansi)I do not see you did something to have the error message visible during the Ajax requests.
At least, surround your h:message with a4j:outputPanel ajaxRendered="true" -
2. Re: Unable to render Error Message <h:message> on JSF page
mail2bansi Jul 27, 2007 4:21 PM (in response to mail2bansi)Hi Sergey
The following snippet should make the error message visible
<ui:include src="messages.xhtml"/>
<h:messages errorClass="error" layout="table" style="width: 100%"/>
It works in almost all cases except in this particular case.
Please note <h:message> belongs to textfield , the onblur event of which loads remaining fields on form which are under <a4j:outputPanel>
I have added ajaxRendered="true" to it but it didnt made any difference<h:inputText id="propertyTag" value="#{deviceBean.tagNumber}" > <a4j:support action="#{deviceBean.loadAssetDetails}" event="onblur" reRender="mypanel" /> </h:inputText> <h:message for="propertyTag" styleClass="errorMessage" />
<a4j:outputPanel id="mypanel" ajaxRendered="true" > <h:panelGrid columns="3" styleClass="detail" columnClasses="label" > <h:outputLabel><h:outputText value="Model" /> </h:outputLabel> <h:inputText id="model" value="#{deviceBean.device.model}" disabled="#{deviceBean.disableMode}"/> <h:message for="model" styleClass="errorMessage" /> </h:panelGrid> </a4j:outputPanel>
public String loadAssetDetails() { try{ namsAsset = deviceManager.getAssetDetails(sourceSystem, tagNumber); }catch(RuntimeException re){ if (re.getMessage().contains("No Asset found")){ System.out.println("Inside Bean No Asset Exception"); FacesUtils.addErrorMessage("errors.NoAsset", sourceSystem, tagNumber); return null; }
public static void addErrorMessage(String key, String arg1, String arg2) { //FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg)); ApplicationFactory factory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY); String bundleName = factory.getApplication().getMessageBundle(); ResourceBundle messages = ResourceBundle.getBundle(bundleName); MessageFormat form = new MessageFormat(messages.getString(key)); String msg = form.format(new Object[] { arg1, arg2 }); System.out.println("Inside Error Message="+msg); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg)); }
-
3. Re: Unable to render Error Message <h:message> on JSF page
sergeysmirnov Jul 27, 2007 4:43 PM (in response to mail2bansi)In the java code, you create a global message (the first param is null). However, on the page, you have only the couple h:message and no h:messages that show the global messages.
Could you explain the point? -
4. Re: Unable to render Error Message <h:message> on JSF page
mail2bansi Jul 27, 2007 5:09 PM (in response to mail2bansi)Sergey
<h:messages> is there on the top of the xhtml page to print global messages. Here is the snippet<ui:include src="messages.xhtml"/> <h:messages errorClass="error" layout="table" style="width: 100%"/>
-
5. Re: Unable to render Error Message <h:message> on JSF page
sergeysmirnov Jul 27, 2007 5:20 PM (in response to mail2bansi)However, it is not updated during the Ajax declaring like this. So what is the point to set the message, but do not show it on the page?