<p:commandButton> won't submit form on first click if <p:inputText> field uses <p:ajax>

北城余情 提交于 2020-01-06 21:26:22

问题


I'm having an issue with the following form:

<h:form>
    <p:outputPanel autoUpdate="true">
        <p:panelGrid columns="2">
            <f:facet name="header">
                <h:outputText value="Edit a Recycler"/>
            </f:facet>

            <p:outputLabel value="Recycler Name" for="recyclerName"/>
            <p:inputText id="recyclerName" value="#{RecyclerAdmin.editItem.company.companyName}" required="true" requiredMessage="You must name the recycler.">
                <p:ajax async="true" />
            </p:inputText>

            <p:outputLabel value="Zip Code" for="zipCode"/>
            <p:inputText id="zipCode" value="#{RecyclerAdmin.editItem.company.primaryAddressId.zip}" required="false">
                <p:ajax event="blur" async="true" update="citystate" listener="#{RecyclerAdmin.zipCodeChanged}"/>
            </p:inputText>

            <p:outputLabel value="City/State"/>
            <c:choose>
                <c:when test="${RecyclerAdmin.editItem.company.primaryAddressId.city != null and RecyclerAdmin.editItem.company.primaryAddressId.city.length() > 0}">
                <h:outputText id="citystate" value="#{RecyclerAdmin.editItem.company.primaryAddressId.city}, #{RecyclerAdmin.editItem.company.primaryAddressId.state}"/>
                </c:when>
                <c:otherwise>
                    <p:spacer id="citystate"/>
                </c:otherwise>
            </c:choose>

            <f:facet name="footer">
                <p:commandButton id="updatebutton" action="#{RecyclerAdmin.update()}" value="Save" ajax="false"/>
                <p:commandButton id="cancelbutton" action="#{RecyclerAdmin.cancel}" value="Cancel" ajax="false" immediate="true"/>
            </f:facet>

        </p:panelGrid>
    </p:outputPanel>
</h:form>

If I make a change to the "Recycler Name" text field, and then immediately click on the save button, the button click highlighting activates, and remains active, but the form does not submit until the button is clicked a second time. If I click somewhere else before clicking on the save button, everything works, and if I remove the ajax async="true" from the recyclerName field, the form also will submit normally, but I need the ajax reference otherwise any changed values in the field are erased when the zipCode field is manipulated.

Any ideas?


回答1:


The problem was caused by the outputPanel autoUpdate="true" tag. i have added specific update field references to the individual ajax tags and the problem is now gone.




回答2:


try different event

try removing async=true

p:ajax event="keyup"

http://www.primefaces.org/showcase/ui/ajax/event.xhtml



来源:https://stackoverflow.com/questions/26043025/pcommandbutton-wont-submit-form-on-first-click-if-pinputtext-field-uses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!