6 Replies Latest reply on Jan 8, 2008 6:49 PM by deibys

    Submitting an AJAX form and displaying messages

    deibys

       

      <a4j:form ajaxSubmit="true" reRender="messages2" id="createUserForm" >
       <a4j:outputPanel ajaxRendered="true">
       <h:messages />
       </a4j:outputPanel>
       <h:panelGrid columns="2" cellspacing="5" >
       <h:outputLabel value="Usuario" for="username" />
       <h:inputText id="username" required="true" value="#{CreateUserBean.userName}" />
       <h:outputLabel value="Contraseña" for="password1" />
       <h:inputSecret id="password1" required="true" value="#{CreateUserBean.password1}" />
       <h:outputLabel value="Confirmar Contraseña" for="password2" />
       <h:inputSecret id="password2" required="true" value="#{CreateUserBean.password2}" />
       <h:outputLabel value="Estado" for="status" />
       <h:selectOneMenu value="#{CreateUserBean.status}" id="status">
       <f:selectItem itemLabel="Activo" itemValue="A" />
       <f:selectItem itemLabel="Inactivo" itemValue="I" />
       </h:selectOneMenu>
       <h:outputLabel value="Fecha Inicio" for="start_date" />
       <rich:calendar id="start_date" datePattern="yyyy-MM -dd HH:mm" value="#{CreateUserBean.startDate}" />
       <h:outputLabel value="Fecha Expiracion" for="expire_date" />
       <rich:calendar id="expire_date" datePattern="yyyy-MM-dd HH:mm" value="#{CreateUserBean.expireDate}" />
      
       <h:commandButton value="Crear Usuario" action="#{CreateUserBean.create}" />
       </h:panelGrid>
      </a4j:form>


      Hello guys,
      I have something I have been dedicating some much time and I would aprreciate your help. I want to submit an form through AJAX, that is fine...but validation messages are not displayed, instead I get the following in the log

      14:20:28,593 INFO [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
      sourceId=j_id_jsp_1029581384_11:createUserForm:username[severity=(ERROR 2), summary=(j_id_jsp_1029581384_11:createUserForm:username: Error de Validación: Valor es necesario.), detail=(j_id_jsp_1029581384_11:createUserForm:username: Error de Validación: Valor es necesario.)]
      sourceId=j_id_jsp_1029581384_11:createUserForm:password2[severity=(ERROR 2), summary=(j_id_jsp_1029581384_11:createUserForm:password2: Error de Validación: Valor es necesario.), detail=(j_id_jsp_1029581384_11:createUserForm:password2: Error de Validación: Valor es necesario.)]
      sourceId=j_id_jsp_1029581384_11:createUserForm:password1[severity=(ERROR 2), summary=(j_id_jsp_1029581384_11:createUserForm:password1: Error de Validación: Valor es necesario.), detail=(j_id_jsp_1029581384_11:createUserForm:password1: Error de Validación: Valor es necesario.)]
      


      What's wrong ?

        • 1. Re: Submitting an AJAX form and displaying messages

          * remove ajaxSubmit="true" reRender="messages2" from the a4j:form
          * replace a4j:form with h:form (optionally)
          * replace:

          <a4j:outputPanel ajaxRendered="true">
           <h:messages />
          </a4j:outputPanel>

          with
          <rich:messages />


          * replace:
          <h:commandButton value="Crear Usuario" action="#{CreateUserBean.create}" />

          with:
          <a4j:commandButton value="Crear Usuario" action="#{CreateUserBean.create}" reRender="messages2" />



          • 2. Re: Submitting an AJAX form and displaying messages

            can you try to use <a4j:messages/> instead <h:messages/>?.

            I'm using <a4j:messages/> and all work fine.

            • 3. Re: Submitting an AJAX form and displaying messages

              Sorry, the correct tag is <rich:messages/>

              • 4. Re: Submitting an AJAX form and displaying messages
                deibys

                Hello Sergey,

                Thanks for the post. I have changed my code but it does not work yet.

                (createUser.jsp)

                <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
                <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
                <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
                <%@ taglib uri="http://richfaces.org/rich" prefix="rich" %>
                
                <h:form id="createUserForm" >
                 <rich:messages />
                 <h:panelGrid columns="2" cellspacing="5" >
                 <h:outputLabel value="Usuario" for="username" />
                 <h:inputText id="username" required="true" value="#{CreateUserBean.userName}" />
                 <h:outputLabel value="Contraseña" for="password1" />
                 <h:inputSecret id="password1" required="true" value="#{CreateUserBean.password1}" />
                 <h:outputLabel value="Confirmar Contraseña" for="password2" />
                 <h:inputSecret id="password2" required="true" value="#{CreateUserBean.password2}" />
                 <h:outputLabel value="Estado" for="status" />
                 <h:selectOneMenu value="#{CreateUserBean.status}" id="status">
                 <f:selectItem itemLabel="Activo" itemValue="A" />
                 <f:selectItem itemLabel="Inactivo" itemValue="I" />
                 </h:selectOneMenu>
                 <h:outputLabel value="Fecha Inicio" for="start_date" />
                 <rich:calendar id="start_date" datePattern="yyyy-MM-dd HH:mm" value="#{CreateUserBean.startDate}" />
                 <h:outputLabel value="Fecha Expiracion" for="expire_date" />
                 <rich:calendar id="expire_date" datePattern="yyyy-MM-dd HH:mm" value="#{CreateUserBean.expireDate}" />
                
                 <a4j:commandButton value="Crear Usuario" />
                 </h:panelGrid>
                </h:form>


                I am not sure if it has to do with the fact this(above) is a jsp file that is included in another file which

                (index.jsp)

                <html>
                <head>
                 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                 <title>JSP Page</title>
                 <style type="text/css">
                 body,
                 html {
                 margin:20;
                 padding:0;
                 }
                 body {
                 min-width:800px;
                 }
                 #wrap {
                 margin:0 auto;
                 width:1024px;
                 }
                 #main {
                 float:right;
                 width:750px;
                 }
                 #sidebar {
                 float:left;
                 width:250px;
                 }
                 #footer {
                 background:#cc9;
                 clear:both;
                 }
                 #footer p {
                 padding:5px;
                 margin:0;
                 }
                 </style>
                </head>
                <body>
                 <f:view>
                 <div id="header">
                 <rich:toolBar>
                 <rich:toolBarGroup>
                 <h:outputText value="Bienvenido #{UserBean.userName} !" />
                 </rich:toolBarGroup>
                 <rich:toolBarGroup location="right">
                 <h:form id="logoutForm" >
                 <h:commandLink id="logout" action="#{LoginManager.logout}" >
                 <h:outputText value="Salir" />
                 </h:commandLink>
                 </h:form>
                 </rich:toolBarGroup>
                 </rich:toolBar>
                 </div>
                 <rich:spacer width="1" height="10" />
                 <div id="main">
                 <a4j:outputPanel id="main2" >
                 <h2><h:outputText value="#{MenuBean.nodeSelectedTitle}" /></h2>
                 <a4j:include viewId="#{MenuBean.optionSelectedUrl}" />
                 </a4j:outputPanel>
                 </div>
                 <div id="sidebar">
                 <rich:panel>
                 <h:form>
                 <rich:tree switchType="client" value="#{MenuBean.treeNode}" var="item" id="navigationMenu"
                 iconLeaf="/images/gear.gif" iconCollapsed="/images/tree_folder_close.gif"
                 iconExpanded="/images/tree_folder_open.gif" icon="false"
                 preserveModel="state" ajaxSubmitSelection="true" reRender="main2"
                 nodeSelectListener="#{MenuBean.processSelection}" >
                
                
                 <rich:treeNode >
                 <h:outputText value="#{item.title}" />
                 </rich:treeNode>
                 </rich:tree>
                 </h:form>
                 </rich:panel>
                 </div>
                 <rich:spacer width="1" height="10" />
                 <div id="footer">
                 <p>@Copyright 2008</p>
                 </div>
                 </f:view>
                </body>
                </html>
                
                


                Please note that red coloured code, might reosolve to include createUser.jsp


                • 5. Re: Submitting an AJAX form and displaying messages

                  does the message is shown if you temporary replace a4j:commandButton with h:commandButton ?

                  • 6. Re: Submitting an AJAX form and displaying messages
                    deibys

                    It does not, but I think I found the issue.

                    I have one treeMenu (div sidebar), which is the base for my Application Navigation, The Bean that supported the tree had "request"scope , i switched it to "session" and messages were coming.

                    Possibiliy some state was lost , that it did not let rebuild the status before submitting ( sounds messy ? ), sorry I still dont know the cause clearly


                    I am not sure if it might be performance, but I would like to keep data in session only necessary , not for navigation. is there a way that when I do thet ajax form submit, I could also submit the status (or variables) for the TREE navigation ?, so i keep the managedBean in "request"

                    deibys