Ok, I obviously need a few buckets of coffee. Here goes the error:

FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "User already exists with this email", "");

should be

FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "User already exists with this email");




----- Original Message ----- From: "Jana Parvanova" <[EMAIL PROTECTED]>
To: "MyFaces Discussion" <[email protected]>
Sent: Wednesday, October 04, 2006 11:53 AM
Subject: Ajax4jsf and JSF messages


Hello!

I am trying to use ajax4jsf and MyFaces. So far everything looks great except for the messages that I cannot show.

Here is my jsp:

<h:inputText id="newEmail" value="#{mbUserBean.newEmail}" styleClass="requiredInput" required="true" size="40"/> <a4j:commandLink reRender="content" value="Add user" actionListener="#{mbUserBean.addUser}" styleClass="commonLink"/>

                       <a4j:outputPanel ajaxRendered="true">
<h:message for="newEmail" errorClass="errorText"/>
                           <h:messages />
                       </a4j:outputPanel>

(According to "The AJAX framework should not append or delete, but only replaces elements on the page. For successful updates, an element with the same ID as in the response must exist in the page. If you want append any code to a page, put in a placeholder for it (any empty element). For the same reason, we recommend placing messages in the AjaxOutput component (since no messages is also a message)." in https://ajax4jsf.dev.java.net/nonav/documentation/ajax-documentation/developerGuide.html)

In the UserBean:

   public void addUser(ActionEvent evt) {

       try {
           UserService.createUser(getNewEmail());
           newEmail = "";
       } catch (DuplicateEmailException ex) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "User already exists with this email", ""); FacesContext.getCurrentInstance().addMessage("form:newEmail", msg);
       }
       return;
   }


And here is what happens:
- When field is empty (that is required="true" fails) both messages appear fine. - When value is not unique (we go into "catch (DuplicateEmailException ex)") the field message is not shown. The <h:messages /> shows my message.

I know ajax4jsf has problems rendering components that are not initially present. But then - I tried to use the suggested in the Developep's Guide approach (with outputPanel) and it does not work for me.
Has anyone had similar experience? Any help will be appreciated.

Thanks,

Jana



Reply via email to