0

Okay, so I have read through stackoverflow and various other portions of the net for a few days, and have not found a solution yet that fixes my issue.

Basically, I have an h:form in a p:dialog with two required fields. When the fields are both filled in, the form successfully submits and the dialog closes. When either or both fields are left blank, required field validation fails and updates the h:messages component in the p:dialog with the appropriate required messages. However, also when validation fails, the AJAX call seems to never "finish" and prevents subsequent calls from being executed. This is seen evident by my p:ajaxStatus component never disappearing from the screen, indicating that something is hanging somewhere. This is remedied by refreshing the page, at which point all other AJAX components begin to function again.

Additionally, I will note that this p:dialog is in a ui:define in a ui:composition, that dumps it into a master template. It is not nested within another h:form.

<p:dialog id="dlgDecision"
                  header="Decision"
                  widgetVar="dialogDecision"
                  modal="false"
                  resizable="false"
                  appendToBody="true">
            <h:form id="fDlgDecision">
                <h:messages id="msgDlgDecision" binding="#{msgform.messages}" errorClass="errormsg" infoClass="infomsg1" layout="table"/>
                <h:outputFormat rendered="#{studentdetailsform.decisionAction == 'A'}">
                    <h:outputText value="Select an accept and admit code."/>
                </h:outputFormat>
                <h:outputFormat rendered="#{studentdetailsform.decisionAction == 'C'}">
                    <h:outputText value="Select a cancel and reason code."/>
                </h:outputFormat>
                <h:panelGrid columns="1">
                    <h:selectOneMenu id="apdcCode"
                                     value="#{studentDetails.apdcCode}"
                                     required="true"
                                     requiredMessage="Please choose a decision code.">
                        <f:selectItem itemLabel="Select Decision Code"/>
                        <f:selectItems value="#{apdcCodes.apdcCodeList}"
                                       var="apdc"
                                       itemValue="#{apdc.apdcCode}"
                                       itemLabel="#{apdc.apdcCode} - #{apdc.apdcDesc}"/>
                    </h:selectOneMenu>
                    <h:selectOneMenu id="admtCode"
                                     value="#{studentDetails.admtCode}"
                                     required="#{studentdetailsform.decisionAction == 'A'}"
                                     requiredMessage="Please choose an admit code."
                                     rendered="#{studentdetailsform.decisionAction == 'A'}">
                        <f:selectItem itemLabel="Select Admit Code"/>
                        <f:selectItems value="#{admtCodes.admtCodeList}"
                                       var="admt"
                                       itemValue="#{admt.admtCode}}"
                                       itemLabel="#{admt.admtCode} - #{admt.admtDesc}"/>
                    </h:selectOneMenu>
                    <h:selectOneMenu id="wrsnCode"
                                     value="#{studentDetails.wrsnCode}"
                                     required="#{studentdetailsform.decisionAction == 'C'}"
                                     requiredMessage="Please choose a reason code."
                                     rendered="#{studentdetailsform.decisionAction == 'C'}">
                        <f:selectItem itemLabel="Select Reason Code"/>
                        <f:selectItems value="#{wrsnCodes.wrsnCodeList}"
                                       var="wrsn"
                                       itemValue="#{wrsn.wrsnCode}"
                                       itemLabel="#{wrsn.wrsnCode} - #{wrsn.wrsnDesc}"/>
                    </h:selectOneMenu>
                    <p:commandButton id="decisionSubmit"
                                     value="Submit Decision"
                                     type="submit"
                                     action="#{mainform.saveDecision}"
                                     ajax="true"
                                     partialSubmit="true"
                                     process="@form"
                                     update="@form msgDlgDecision"
                                     oncomplete="if (!args.validationFailed) dialogDecision.hide()"/>
                </h:panelGrid>
            </h:form>
        </p:dialog>

Some things I have already done in my debugging and troubleshooting:
- Moved the h:form into the p:dialog
- Made the backing bean with the values for the rendered attribute on the required fields ViewScoped (was having an issue with only some of the required messages showing, this resolved this problem)
- Added appendToBody="true" to p:dialog
- Added if (!args.validationFailed) to the oncomplete event of p:dialog
- Tried making the required fields NOT conditional (removed rendered attributes) to be sure this wasn't being caused by failed validation on non-rendered components (grasping at straws...)

EDIT: Here is a console dump from Chrome. Javascript error gets thrown when submitting the form with null required fields.

Uncaught SyntaxError: Unexpected token { jquery.js:14
bG.extend.parseJSON jquery.js:14
PrimeFaces.ajax.AjaxUtils.handleResponse primefaces.js:1
PrimeFaces.ajax.AjaxResponse primefaces.js:1
j.success primefaces.js:1
bZ jquery.js:14
b7.fireWith jquery.js:14
ca jquery.js:21
bZ

EDIT 2: Below are the only two JavaScript imports, both of which are in my template that is applied to the page via the ui:define and ui:composition mentioned above.

<h:outputScript library="primefaces" name="jquery/jquery.js" />
        <script type="text/javascript" src="#{request.contextPath}/resources/scripts/jscript.js" />

The first import will force Primefaces to import jQuery into the page, even if there are no components on the page that utilize JavaScript. This is to allow my custom scripts in jscript.js to use jQuery reliably.

Other information:
JSF 2.1
Primefaces 3.4.2
Tomcat 6.0

4

3 回答 3

0

不要手动导入 jQuery.js,因为这已经由 PrimeFaces 隐式完成(它在后台使用 jQuery)。您可以删除该行。

您还应该看到一些导入自定义 js 文件h:outputScript的示例,例如:

<h:outputScript library="scripts" name="jscript.js" />

但这可能不是您的问题的原因,这只是提示更好的 JSF 设计。

于 2013-03-12T15:12:28.617 回答
0

我在我的应用程序中遇到了完全相同的问题。真正的问题是重复的 jar 问题。

我的应用程序中有两个 primefaces jar,一个在 WEB-INF/lib 目录下,另一个在 ear/lib 目录下。一旦我删除了 WEB-INF 下的那个,一切都开始按预期工作。

您可以通过搜索 js 异常在网上找到解决方案。

于 2013-06-28T11:07:25.517 回答
0

今天,在我下载 PrimeFaces 4.0 快照 (2013-05-09) 并测试我的应用程序后,Google Chrome 中出现了类似的错误。

基本上,我必须从通过 JSON 从 bean 发送到 p:schedule 的数据中删除单引号。由于错误提到了“解析 JSON”和“意外的 '”(意外的单引号),我转到数据的数据表视图(而不是 p:schedule)并发现某些数据嵌入了单引号。所以,我从数据中删除了单引号,这为我解决了这个问题。

请点击下面的论坛主题网址。

PF 4.0 SNAPSHOT 2013-05-09:计划不工作

于 2013-05-10T22:51:23.787 回答