2 Replies Latest reply on Oct 30, 2007 10:47 AM by Arbi Sookazian

    main h:form is submitted when I hit enter in a4j:form

    Arbi Sookazian Master

      As below code, a4j:form is embedded inside a modalPanel. when i enter data in the inputText and hit enter button on keyboard, the main form in the xhtml is submitted and the entire screen/JSF is re-rendered. i only want the a4j:form to be submitted (like when I click the submit button below) and then the modalPanel to close.

      how can I accomplish this?

      one was is add onkeypress event handler for <h:inputText> and determine if the key pressed was the enter key. if so, exec noteAction.submit.

      any better way?

      <rich:modalPanel id="mp" minHeight="200" minWidth="450"
       height="200" width="500" zindex="2000">
       <f:facet name="header">
       <h:outputText value="#{noteAction.header}" />
       </f:facet>
       <f:facet name="controls">
       <h:graphicImage value="/img/icon_edit.gif" style="cursor:pointer" onclick="Richfaces.hideModalPanel('mp')" />
       </f:facet>
       <a4j:form id="a4jForm">
       <h:inputText id="noteText" value="#{noteAction.noteText}"/>
       <h:inputHidden id="rowIndex" value="noteAction.rowIndex"/>
       <h:inputHidden id="colName" value="noteAction.colName"/>
       <h:inputHidden id="siteId" value="noteAction.siteId"/>
       <h:inputHidden id="employeeNumber" value="noteAction.employeeNumber"/>
       <a4j:commandButton value="submit" action="#{noteAction.submit}" onclick="showNoteGraphic();Richfaces.hideModalPanel('mp')"/>
       </a4j:form>
       </rich:modalPanel>


        • 1. Re: main h:form is submitted when I hit enter in a4j:form
          Ilya Shaikovsky Master

          you sure you do not have forms nested?

          • 2. Re: main h:form is submitted when I hit enter in a4j:form
            Arbi Sookazian Master

            here is the entire .xhtml:

            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
             xmlns:s="http://jboss.com/products/seam/taglib"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:rich="http://richfaces.ajax4jsf.org/rich"
             xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
             template="layout/template.xhtml">
            
            
            
            <ui:define name="body">
            
             <script type="text/javascript"
             src="seam/resource/remoting/resource/remote.js">
             </script>
            
             <script type="text/javascript"
             src="seam/resource/remoting/interface.js?noteAction">
             </script>
            
             <script type="text/javascript"
             src="js/securityAudit.js">
             </script>
            
             <h:messages globalOnly="true" styleClass="message"/>
            
             <rich:modalPanel id="mp" minHeight="200" minWidth="450"
             height="200" width="500" zindex="2000">
             <f:facet name="header">
             <h:outputText value="#{noteAction.header}" />
             </f:facet>
             <f:facet name="controls">
             <h:graphicImage value="/img/icon_edit.gif" style="cursor:pointer" onclick="Richfaces.hideModalPanel('mp')" />
             </f:facet>
             <a4j:form id="a4jForm">
             <h:inputText id="noteText" value="#{noteAction.noteText}"/>
             <h:inputHidden id="rowIndex" value="noteAction.rowIndex"/>
             <h:inputHidden id="colName" value="noteAction.colName"/>
             <h:inputHidden id="siteId" value="noteAction.siteId"/>
             <h:inputHidden id="employeeNumber" value="noteAction.employeeNumber"/>
             <a4j:commandButton value="submit" action="#{noteAction.submit}" onclick="showNoteGraphic();Richfaces.hideModalPanel('mp')"/>
             </a4j:form>
             </rich:modalPanel>
            
             <h:form>
             <h:inputText value="#{securityAuditAction.networkId}"/>
             <h:commandButton value="Submit"/>
             </h:form>
            
             <h:form id="mainForm">
             <h:outputText value="No Direct Reports" rendered="#{myAuditList != null and myAuditList.rowCount==0}"/>
             <h:dataTable id="dataTable1" value="#{myAuditList}" var="myRow" rendered="#{myAuditList.rowCount>0}"
             bgcolor="#F1F1F1" border="10" width="100%" cellpadding="0" cellspacing="0"
             dir="LTR" frame="hsides">
             <h:column>
             <f:facet name="header">Employee Name</f:facet>
            
             <!-- siteId and employeeNumber hidden fields are used for all radio buttons -->
             <h:outputText id="empName" value="#{myRow[0].id.employeeName}"/>
             <h:inputHidden id="siteId" value="#{myRow[0].id.siteId}"/>
             <h:inputHidden id="employeeNumber" value="#{myRow[0].id.employeeNumber}"/>
             </h:column>
            
             <h:column>
             <f:facet name="header">SiteId</f:facet>
            
             <h:outputText value="#{myRow[0].id.siteId}"/>
             </h:column>
            
             <h:column>
             <f:facet name="header">EmployeeNumber</f:facet>
            
             <h:outputText value="#{myRow[0].id.employeeNumber}"/>
             </h:column>
            
             <h:column>
             <f:facet name="header">Account Approved?</f:facet>
            
             <h:selectOneRadio id="accountApprovedRB" value="#{myRow[1].icomsAccountApproved}" onclick="processNote(this, #{myAuditList.getRowIndex()}, 'accountApproved');checkForSubmit(#{myAuditList.getRowIndex()})">
             <f:selectItems value="#{securityAuditAction.securityAuditRadioButtons}" />
             </h:selectOneRadio>
             <h:graphicImage id="acctGraphic" value="/img/icon_edit.gif" onclick="editNote(#{myAuditList.getRowIndex()}, 'accountApproved');" style="visibility:hidden"/>
             </h:column>
            
             <h:column>
             <f:facet name="header">Security Level Approved?</f:facet>
             <h:selectOneRadio id="securityLevelApprovedRB" value="#{myRow[1].securityLevelApproved}" onclick="processNote(this, #{myAuditList.getRowIndex()}, 'secLevelApproved');checkForSubmit(#{myAuditList.getRowIndex()})">
             <f:selectItems value="#{securityAuditAction.securityAuditRadioButtons}" />
             </h:selectOneRadio>
             <h:graphicImage id="securityLevelGraphic" value="/img/icon_edit.gif" onclick="editNote(#{myAuditList.getRowIndex()}, 'secLevelApproved');" style="visibility:hidden"/>
             </h:column>
            
             <h:column>
             <f:facet name="header">Adjustment Limit Approved?</f:facet>
             <h:selectOneRadio id="adjustmentLimitApprovedRB" value="#{myRow[1].adjustmentLimitApproved}" onclick="processNote(this, #{myAuditList.getRowIndex()}, 'adjLimitApproved');checkForSubmit(#{myAuditList.getRowIndex()})">
             <f:selectItems value="#{securityAuditAction.securityAuditRadioButtons}" />
             </h:selectOneRadio>
             <h:graphicImage id="adjLimitGraphic" value="/img/icon_edit.gif" onclick="editNote(#{myAuditList.getRowIndex()}, 'adjLimitApproved');" style="visibility:hidden"/>
             </h:column>
            
             <h:column>
             <h:commandButton id="submitEmployee" value="Submit" action="#{securityAuditAction.submit}" style="visibility:hidden"/>
             </h:column>
             </h:dataTable>
            
             <!-- <h:commandButton value="submit" action="#{securityAuditAction.submit}" rendered="#{myAuditList.rowCount>0}"/> -->
            
             </h:form>
            
            </ui:define>
            </ui:composition>