![](/img/trans.png)
[英]close richfaces popupPanel if method call has certain outcome
[英]render richfaces popupPanel after bean method is finished
我有一个简单的问题,如果我的托管bean出现问题,我想显示一个弹出窗口。 bean使用getter / setter方法保存可以引发的异常列表。
xhtml看起来像这样
<rich:panel>
<h:form>
<a4j:commandButton value="Compute Mission"
action="#{missionHandler.generateMissionFeasability}"
render="popupPanel">
</a4j:commandButton>
</h:form>
</rich:panel>
<rich:popupPanel id="popupPanel" modal="true" autosized="true"
resizeable="false" moveable="false" rendered="#{not empty missionHandler.exceptions}">
<f:facet name="header">
<h:outputText value="Exceptions raised during the processing " />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#"
onclick="#{rich:component('popupPanel')}.hide();return false;">
</h:outputLink>
</f:facet>
</rich:popupPanel>
如你所见,我有一个命令按钮,应该在bean中调用generateMissionFeasibility方法。 该方法将(除其他外)在例外列表中添加异常。
我想查看列表(如果它是否为空)以显示弹出窗口
上面的代码不起作用,因为我认为弹出窗口是在bean的方法结束之前呈现的,并且列表在开头是空的。
一旦渲染弹出面板的一种方法是改变
rendered="#{not empty missionHandler.exceptions}"
至
show="#{not empty missionHandler.exceptions}"
代码不起作用,因为第一missionHandler.exceptions
渲染视图时, missionHandler.exceptions
将为空,这意味着popupPanel
永远不会进入浏览器。 对reRender popupPanel
后续请求将失败,因为在DOM中找不到组件。
对于要进行ajax更新的组件,它必须已经在浏览器的DOM中,这就是ajax的工作方式。 因此,解决方案是将弹出面板的内容包装在将始终呈现的组件中。
除此之外,即使您的渲染正确,您的弹出窗口也只会放在DOM中。 你实际上需要在弹出窗口上调用show()
来让它显示出来
然而,为了实现你想要的,一个更好的选择将是
有条件地使用javascript显示弹出窗口。 如果满足条件,则为弹出窗口调用show()
函数。 否则,将调用一个空的,无用的javascript函数。
<a4j:commandButton value="Compute Mission" action="#missionHandler.generateMissionFeasability}" oncomplete="#{not empty missionHandler.exceptions ? #{rich:component('popupPanel')}.show()" : doNothing()}" render="popupPanel"> </a4j:commandButton>
对于doNothing js:
<script> function doNothing(){} <script/>
将渲染条件从模态面板中取出
编辑:此外,弹出组件上的show
属性可以基于与oncomplete
属性相同的EL条件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.