Wednesday, May 6, 2009

Integration ICEfaces message and Seam’s FacesMessages

How to display error/confirmation message wherever you want

  1. – Without JSF UI control's Id and help of ice:messge's id attribute

In Backing bean -

  1. import org.jboss.seam.faces.FacesMessages;
  2. @In private FacesMessages facesMessages;
  3. facesMessages.addToControl("msgId", "Saved successfully!!!");

In JSF/Facelets page –

Put the following code wherever you want the error to be displayed -

<ice:message
id="msgId" for="msgId"
/>

  1. With make use of JSF UI control's Id

In Backing bean -

  1. import org.jboss.seam.faces.FacesMessages;
  2. @In private FacesMessages facesMessages;
  3. facesMessages.addToControl("jsfUIComponentId", "You have error message in the first name");

In JSF/Facelets page –

Put the following code wherever you want the error to be displayed -

<ice:outputText
id="jsfUIComponentId"
value="First Name"
/>

<br/>

<br/>

<!-- without id attribute since we added in outputText UI component -->

<ice:message
for="jsfUIComponentId"
/>

Note: To use facesMessages.addToControl("someJSF_UIComponentId", "some msg") - we need some UI component with Id's values with the same value which we used in the backing bean.

No comments: