【发布时间】:2013-12-28 00:25:36
【问题描述】:
在使用 RF 4 的单页 JSF 2.1 应用程序中,会有很多弹出窗口用于不同的表单来编辑数据。仅当单击 GUI 中的某个按钮时才应显示表单。由于我无法在原始页面加载时创建所有弹出窗口,包括内容和支持 bean,因此我使用延迟加载创建它们,类似于此问题中提出的第二个答案:Richfaces modalPanel load with Ajax
<a4j:outputPanel id="container">
<c:if test="#{popupController.isPopupVisible(popup.id)}">
<f:subview id="view">
<rich:popupPanel id="popup" show="true" modal="false" autosized="true" resizeable="false" style="z-index:10000; background-color:#FFF;">
<f:facet name="header">
<h:outputText value="#{popup.title}" />
</f:facet>
<f:facet name="controls">
<h:form id="closeButtonform">
<a4j:commandLink id="closePopup" render="container" action="#{popupController.hidePopup(popup.id)}" onbeforedomupdate="#{rich:component('popup')}.hide(); return false;">X</a4j:commandLink>
</h:form>
</f:facet>
<rich:extendedDataTable id="table" value="#{itemBean.items}" var="item">
...
</rich:extendedDataTable>
</rich:popupPanel>
</f:subview>
</c:if>
</a4j:outputPanel>
<h:form id="openButtonForm">
<a4j:commandLink id="openPopup" render="container" action="#{popupController.showPopup(popup.id)}" />
</h:form>
backing bean 不做任何魔术,只是存储数据,所以它们被忽略了。
目前的工作是打开和关闭显示/隐藏弹出窗口的弹出链接,并且仅在需要时创建包括弹出内容的支持 bean 在内的内容。我遇到的问题是弹出窗口内的组件(本示例中的 rich:extendedDataTable)已显示,但 JSF/Richfaces/Ajax 以某种方式未正确处理它们。让我进一步详细说明:当 c:if 测试在页面初始显示期间评估为 true 时,一切正常,JavaScript RichFaces.$('popup:view:table') 产生与表格关联的正确 RF JavaScript 对象。我可以随意关闭/打开弹出窗口,没有任何问题。但是,当页面加载时最初不存在弹出窗口然后使用按钮打开时,我收到以下 JS 错误。
Uncaught TypeError: Cannot call method 'addCSSText' of undefined popup.xhtml:1
(anonymous function) popup.xhtml:1
runScripts jsf.js.xhtml:1
doUpdate jsf.js.xhtml:1
response jsf.js.xhtml:1
richfaces.queue.response richfaces-queue.js.xhtml:413
jsf.ajax.response richfaces-queue.js.xhtml:50
onComplete jsf.js.xhtml:1
AjaxEngine.req.xmlReq.onreadystatechange jsf.js.xhtml:1
Uncaught TypeError: Cannot call method 'addLocale' of undefined popup.xhtml:1
(anonymous function) popup.xhtml:1
runScripts jsf.js.xhtml:1
doUpdate jsf.js.xhtml:1
response jsf.js.xhtml:1
richfaces.queue.response richfaces-queue.js.xhtml:413
jsf.ajax.response richfaces-queue.js.xhtml:50
onComplete jsf.js.xhtml:1
AjaxEngine.req.xmlReq.onreadystatechange jsf.js.xhtml:1
Uncaught TypeError: undefined is not a function popup.xhtml:1
(anonymous function) popup.xhtml:1
runScripts jsf.js.xhtml:1
doUpdate jsf.js.xhtml:1
response jsf.js.xhtml:1
richfaces.queue.response richfaces-queue.js.xhtml:413
jsf.ajax.response richfaces-queue.js.xhtml:50
onComplete jsf.js.xhtml:1
AjaxEngine.req.xmlReq.onreadystatechange
然后相同的 JavaScript RichFaces.$('popup:view:table') 产生 undefined 并且弹出窗口中的表格无法正确呈现。似乎所有依赖于 RF JavaScript(如列格式、滚动条等)的东西都没有初始化,在某些情况下也没有应用 CSS。在这里,我关闭/打开弹出窗口的频率也无关紧要,它总是坏掉。
有什么想法可以直接在 JSF 中或在打开按钮的 oncomplete 上的 JavaScript 中解决这个问题吗?
【问题讨论】:
-
虽然它可能不是问题的核心,但不要使用嵌套表单。如果您需要限制执行范围,请使用
<h:form>,然后使用<a4j:region>之类的内容。 -
谢谢@Makhiel,实际上我没有嵌套表单。我从我的代码中剥离了一点点。我现在修好了,看看
<a4j:region>是否适用于这种情况。
标签: ajax jsf jsf-2 popup richfaces