,我有一个单页的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 ...>
我从这个调试输出中更聪明。有没有人见过这样的东西?
答案 0 :(得分:0)
事实证明,对此的回答是jsf ajax的通用:
JSF 2.0, malformedXML when using ajax on a commandlink
我将上面的命令按钮代码放到面板中并更改渲染以呈现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来渲染,按钮是不够的。