0

,我有一个单页 RichFaces 应用程序(RichFaces 4.2.3,JSF 2.0.3),它有一个单一的表单,我通过用 a4j:ajax 包装面板来“ajaxified”所有组件。提交按钮在这个包装之外,但我使用的是 a4j:commandButton。通过调用 bean isValid() 方法有条件地禁用该按钮。当 bean 中的条件正确时,按钮将被启用。

          <a4j:commandButton id="submitButton"
            value="Save to Database"
            disabled="#{!submission.isValid()}" render="bodyPanel"
            action="#{submission.submitAnnotations}">
            <rich:componentControl target="savedPopup"
              event="complete" operation="show" />
            <rich:tooltip id="submitButtonTooltip" mode="client"
              target="submitButton">Submit the completed annotations to TAIR.
            </rich:tooltip>
          </a4j:commandButton>

我已经在可能影响有效性的各个字段上呈现了属性。当条件正确时,按钮启用,但不是提交按钮,它看起来像这样:

<input id="bodyForm:submitButton" name="undefined" onclick="return false;" value="undefined" type="submit">

所以标签从“保存到数据库”变为“未定义”。如果我单击该按钮,则不会发生任何事情(未调用 submitAnnotations 方法)。在此过程中的任何时候都没有 javascript 错误,但看起来有 ajax 错误:

info [11:04:32.529]: Received 'begin' event from <span id=bodyForm:locusTable:0:functionTable:0:functionTerm class=rf-au termAutoStyle ...>
info [11:04:32.587]: Received 'beforedomupdate' event from <span id=bodyForm:locusTable:0:functionTable:0:functionTerm class=rf-au termAutoStyle ...>
info [11:04:32.590]: Listing content of response changes element:
Element update for id=bodyForm:locusTable:0:j_idt48
<update id="bodyForm:locusTable:0:j_idt48"><![CDATA[<span class="rf-msg errorMessage" id="bodyForm:locusTable:0:j_idt48"></span>]]></update>
Element update for id=bodyForm:locusTable:0:j_idt53
<update id="bodyForm:locusTable:0:j_idt53"><![CDATA[<span class="rf-msg errorMessage" id="bodyForm:locusTable:0:j_idt53"></span>]]></update>
Element update for id=bodyForm:locusTable:0:functionTable:0:functionTerm
<update id="bodyForm:locusTable:0:functionTable:0:functionTerm"><![CDATA[<span class="rf-au termAutoStyle" id="bodyForm:locusTable:0:functionTable:0:functionTerm"><input id="bodyForm:locusTable:0:functionTable:0:functionTermValue" name="bodyForm:locusTable:0:functionTable:0:functionTermValue" type="hidden" /><span><input autocomplete="off" class="rf-au-fnt rf-au-inp " id="bodyForm:locusTable:0:functionTable:0:functionTermInput" name="bodyForm:locusTable:0:functionTable:0:functionTermInput" type="text" value="phytoene dehydrogenase activity" tabindex="8" /></span><div class="rf-au-lst-cord" id="bodyForm:locusTable:0:functionTable:0:functionTermList"><div class="rf-au-shdw"><div class="rf-au-shdw-t"></div><div class="rf-au-shdw-l"></div><div class="rf-au-shdw-r"></div><div class="rf-au-shdw-b"></div><div class="rf-au-lst-dcrtn termAutoPopupStyle"><div class="rf-au-lst-scrl"><table id="bodyForm:locusTable:0:functionTable:0:functionTermItems" class="rf-au-tbl"><tbody></tbody></table></div></div></div></div><script type="text/javascript">new RichFaces.ui.Autocomplete("bodyForm:locusTable:0:functionTable:0:functionTerm", "bodyForm:locusTable:0:functionTable:0:functionTermInput", {"buttonId":"bodyForm:locusTable:0:functionTable:0:functionTermButton","onchange":function(event){RichFaces.ajax(this,event,{"parameters":{"javax.faces.behavior.event":"change","org.richfaces.ajax.component":"bodyForm:locusTable:0:functionTable:0:functionTerm"} ,"sourceId":this} )},"minChars":2} );</script></span>]]></update>
Element update for id=bodyForm:locusTable:0:functionTable:0:fMethodMessage
<update id="bodyForm:locusTable:0:functionTable:0:fMethodMessage"><![CDATA[<span class="rf-msg errorMessage" id="bodyForm:locusTable:0:functionTable:0:fMethodMessage"></span>]]></update>
Element update for id=bodyForm:submitButton
<update id="bodyForm:submitButton"><![CDATA[<span id="bodyForm:submitButtonTooltip" style="display: none;"><span id="bodyForm:submitButtonTooltip:wrp" class="rf-tt" style="z-index:1000"><span id="bodyForm:submitButtonTooltip:cntr" class="rf-tt-cntr"><span id="bodyForm:submitButtonTooltip:content" class="rf-tt-cnt">Submit the completed annotations to TAIR.</span></span></span></span><input id="bodyForm:submitButton" name="bodyForm:submitButton" onclick="return false;" value="Save to Database" disabled="disabled" type="submit" />]]></update>
Element update for id=bodyForm:submissionMessages
<update id="bodyForm:submissionMessages"><![CDATA[<span class="rf-msgs " id="bodyForm:submissionMessages"></span>]]></update>
Element update for id=javax.faces.ViewState
<update id="javax.faces.ViewState"><![CDATA[-597202710648046990:-4469349859912622104]]></update>
Element extension for id=org.richfaces.extension
<extension id="org.richfaces.extension"><complete>new RichFaces.ui.Tooltip("bodyForm:submitButtonTooltip",{"ajax":{"incId":"1"} ,"target":"bodyForm:submitButton","offset":[10,10] } );new RichFaces.ui.Message("bodyForm:locusTable:0:j_idt48",{"forComponentId":"bodyForm:locusTable:0:symbol","showSummary":false,"showDetail":true} );new RichFaces.ui.Message("bodyForm:locusTable:0:j_idt53",{"forComponentId":"bodyForm:locusTable:0:fullName","showSummary":false,"showDetail":true} );new RichFaces.ui.Message("bodyForm:locusTable:0:functionTable:0:fMethodMessage",{"forComponentId":"bodyForm:locusTable:0:functionTable:0:fMethod","showDetail":true} );new RichFaces.ui.Message("bodyForm:submissionMessages",{"showDetail":true,"globalOnly":true,"isMessages":true} );</complete></extension>
error[11:04:32.593]: Received 'error@malformedXML' event from <span id=bodyForm:locusTable:0:functionTable:0:functionTerm class=rf-au termAutoStyle ...>
error[11:04:32.594]: [200] undefined: undefined
info [11:04:32.594]: Received 'complete' event from <span id=bodyForm:locusTable:0:functionTable:0:functionTerm class=rf-au termAutoStyle ...>

从这个调试输出中我一点也不聪明。有没有人见过这样的事情?

4

1 回答 1

0

事实证明,这个问题的答案对于 jsf ajax 来说是通用的:

JSF 2.0,在命令链接上使用 ajax 时格式错误的 XML

我将上面的命令按钮代码放入面板中,并将渲染更改为渲染 buttonPanel 而不是 submitButton,现在它可以像宣传的那样工作:

      <a4j:outputPanel id="buttonPanel">
        <h:panelGrid columns="3">
          <a4j:commandButton id="submitButton"
            value="Save to Database"
            disabled="#{!submission.isValid()}" render="bodyPanel"
            action="#{submission.submitAnnotations}">
          </a4j:commandButton>
       ...

渲染需要面板中的 HTML 来渲染,按钮是不够的。

于 2013-08-15T18:48:18.733 回答