You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Julien Martin <ba...@gmail.com> on 2008/07/31 12:37:58 UTC

Problem with h:message and ajax

Hello,
I noticed a strange problem occurring with my richfaces application. It is
as follows:
I have a contact form with "real-time" validation of each field. When a
valid submission of the form occurs, the form is reRendered and strangely,
the first field shows a validation passed status even though it is empty.

Here is my jsp:

[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="
http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html" xmlns:f="
http://java.sun.com/jsf/core" xmlns:rest="http://restfaces.dev.java.net"
    xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="
http://richfaces.org/rich">
<body>
<ui:composition template="/template.xhtml">

    <ui:define name="title">
        <title><h:outputText value="todo: accueil" /></title>
    </ui:define>
    <ui:define name="body">
        <a4j:outputPanel id="wrapper" layout="block" styleClass="wrapper">
            <rest:link value="contactAction" hreflang="fr" lang="fr">
                <f:param name="language" value="fr" />
                <h:outputText value="#{msg['langue.francais.libelle']}" />
            </rest:link>
            <rest:link value="contactAction" hreflang="en" lang="en">
                <f:param name="language" value="en" />
                <h:outputText value="#{msg['langue.anglais.libelle']}" />
            </rest:link>
            <br />
            <br />
            <a4j:outputPanel rendered="#{contactView.envoiReussi}"
ajaxRendered="true">
                <h:outputText value="envoi reussi todo"/>
            </a4j:outputPanel>
            <a4j:form id="formulaireContact" reRender="wrapper">
                <h:panelGrid columns="3"
columnClasses="libellesColonne,champsColonne,validiteColonne">
                    <f:facet name="header">
                        <a4j:outputPanel layout="block"
styleClass="formulaireContactHeader">
                            <h:outputText value="todo header" />
                        </a4j:outputPanel>
                    </f:facet>
                    <h:outputText value="#{msg['message.from.email']}" />
                    <a4j:outputPanel id="fromEmail">
                        <a4j:region id="fromEmailRegion">
                            <h:inputText id="emailI"
value="#{contactView.message.email}" required="true"

requiredMessage="#{msg['message.valeurRequise.email']}"
validatorMessage="#{msg['message.erreur.email']}"
binding="#{contactView.bb.emailI}">
                                <a4j:support  id="emailS" event="onblur"
reRender="fromEmail, emailMP" ajaxSingle="true"
actionListener="#{contactView.valider}" limitToList="true"
ignoreDupResponses="true" />
                                <f:validator
validatorId="adresseEmailValidator" />
                            </h:inputText>
                            <a4j:status>
                                <f:facet name="start">
                                    <h:graphicImage
value="#{img['ajax-loader']}" />
                                </f:facet>
                            </a4j:status>
                        </a4j:region>
                    </a4j:outputPanel>
                    <a4j:outputPanel id="emailMP">
                        <h:message for="emailI" infoClass="champValide" />
                    </a4j:outputPanel>

                    <h:outputText value="#{msg['message.from.nom']}" />
                    <a4j:outputPanel id="nom">
                        <a4j:region id="nomRegion">
                            <h:inputText id="nomI"
value="#{contactView.message.nom}" required="true"

requiredMessage="#{msg['message.valeurRequise.nom']}"
validatorMessage="todo: nom non valide" binding="#{contactView.bb.nomI}">
                                <a4j:support id="nomS" event="onblur"
reRender="nom, nomMP" ajaxSingle="true"
actionListener="#{contactView.valider}" limitToList="true" />
                                <f:validateLength minimum="2" />
                            </h:inputText>
                            <a4j:status>
                                <f:facet name="start">
                                    <h:graphicImage
value="#{img['ajax-loader']}" />
                                </f:facet>
                            </a4j:status>
                        </a4j:region>
                    </a4j:outputPanel>
                    <a4j:outputPanel id="nomMP">
                        <h:message for="nomI" infoClass="champValide" />
                    </a4j:outputPanel>

                    <h:outputText value="#{msg['message.sujet']}" />
                    <a4j:outputPanel id="sujet">
                        <a4j:region id="sujetRegion">
                            <h:inputText id="sujetI"
value="#{contactView.message.sujetMessage}" required="true"

requiredMessage="#{msg['message.valeurRequise.sujet']}"
validatorMessage="#{msg['message.erreur.sujet']}"
binding="#{contactView.bb.sujetI}">
                                <a4j:support id="sujetS" event="onblur"
reRender="sujet, sujetMP" ajaxSingle="true"
actionListener="#{contactView.valider}" limitToList="true"/>
                                <f:validateLength minimum="2" />
                            </h:inputText>
                            <a4j:status>
                                <f:facet name="start">
                                    <h:graphicImage
value="#{img['ajax-loader']}" />
                                </f:facet>
                            </a4j:status>
                        </a4j:region>
                    </a4j:outputPanel>
                    <a4j:outputPanel id="sujetMP">
                        <h:message for="sujetI" infoClass="champValide" />
                    </a4j:outputPanel>

                    <h:outputText value="#{msg['message.corps']}" />
                    <a4j:outputPanel id="corps">
                        <a4j:region>
                            <h:inputTextarea id="corpsI"
value="#{contactView.message.corpsMessage}" cols="20" rows="5"
required="true"

requiredMessage="#{msg['message.valeurRequise.corps']}"
validatorMessage="#{msg['message.erreur.corps']}"
binding="#{contactView.bb.corpsI}">
                                <a4j:support id="corpsS" event="onblur"
reRender="corps, corpsMP" ajaxSingle="true"
actionListener="#{contactView.valider}" />
                                <f:validateLength minimum="20" />
                            </h:inputTextarea>
                            <a4j:status>
                                <f:facet name="start">
                                    <h:graphicImage
value="#{img['ajax-loader']}" />
                                </f:facet>
                            </a4j:status>
                        </a4j:region>
                    </a4j:outputPanel>
                    <a4j:outputPanel id="corpsMP">
                        <h:message for="corpsI" infoClass="champValide"
style="vertical-align: top" />
                    </a4j:outputPanel>

                    <a4j:outputPanel/>
                    <a4j:outputPanel>
                        <rich:paint2D id="captcha"
width="#{contactView.captchaWidth}" height="#{contactView.captchaHeight}"
format="jpeg"
                            paint="#{contactView.paintCaptcha}">
                            <f:attribute name="alt" value="todo" />
                        </rich:paint2D>
                    </a4j:outputPanel>
                    <a4j:outputPanel />

                    <a4j:outputPanel>
                        <h:outputText value="todo Text on Image:" />
                    </a4j:outputPanel>
                    <a4j:outputPanel id="secureText">
                        <h:inputText id="secureTextI"
value="#{contactView.secureText}" size="20" required="true"
binding="#{contactView.bb.secureTextI}">
                            <f:validator validatorId="captchaValidator" />
                        </h:inputText>
                    </a4j:outputPanel>
                    <a4j:outputPanel id="secureTextMP">
                        <h:message for="secureTextI" />
                    </a4j:outputPanel>

                    <f:facet name="footer">
                        <a4j:outputPanel layout="block"
styleClass="formulaireContactFooter">
                            <a4j:commandButton
value="#{msg['message.envoyer']}" action="#{contactView.envoyer}"/>
                        </a4j:outputPanel>
                    </f:facet>
                </h:panelGrid>
            </a4j:form>
            <a4j:outputPanel layout="block" styleClass="push" />
            <a4j:log popup="false" level="ALL" style="width: 800px; height:
600px;"></a4j:log>
        </a4j:outputPanel>
    </ui:define>
</ui:composition>
</body>
</html>
[/code]

Here is the managed bean method upon which submission is performed:

[code]
    public String envoyer() {
        log.debug("envoyer");
        service.envoyerMessage(this.message);
        try {
            service.envoyerSms(this.message);
        } catch (MalformedURLException ex) {
            log.debug(ex.fillInStackTrace());//todo
        } catch (IOException ex) {
            log.debug(ex.fillInStackTrace());//todo
        }
        this.bb.setLocalValuesSet(false);
        this.bb.setSubmittedValues(null);
        this.bb.setValues("");
        this.envoiReussi = true;
        return null;
    }
[/code]

Can anyone tell me why the first h:message located within the following
panel: (emailMP) displays this strange behavior?

Thanks in advance,

Julien.