You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Jana Parvanova <ja...@sirma.bg> on 2006/10/04 10:53:18 UTC
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
Re: Ajax4jsf and JSF messages
Posted by Jurgen Lust <Ju...@gmail.com>.
Try adding the layout="inline" attribute to your outputPanel.
<a4j:outputPanel ajaxRendered="true" layout="inline">
Jurgen
Op wo, 04-10-2006 te 11:53 +0300, schreef Jana Parvanova:
> 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
>
>
--
____________________________________________________
Jurgen Lust
email: jlust@apache.org
blog: http://jroller.com/page/jurgenlust
____________________________________________________
Re: Ajax4jsf and JSF messages
Posted by Jana Parvanova <ja...@sirma.bg>.
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" <ja...@sirma.bg>
To: "MyFaces Discussion" <us...@myfaces.apache.org>
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
>
>