【问题标题】:render richfaces popupPanel after bean method is finishedbean方法完成后渲染richfaces popupPanel
【发布时间】:2013-02-24 18:32:12
【问题描述】:

我有一个简单的问题,如果我的托管 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 方法。 该方法将(除其他外)在异常列表中添加异常。

我想检查列表(是否为空)以显示弹出窗口

上面的代码不起作用,因为我认为popup是在bean中的方法结束之前渲染的,并且列表一开始是空的。

【问题讨论】:

  • 尝试将面板封装在内部,例如&lt;h:panelGroup id="group"&gt;,并将commandButtonrender属性更改为render="group"

标签: jsf richfaces


【解决方案1】:

在渲染后显示弹出面板的一种方法是更改​​

rendered="#{not empty missionHandler.exceptions}"

show="#{not empty missionHandler.exceptions}"

【讨论】:

    【解决方案2】:

    代码不起作用,因为第一次要渲染视图时,missionHandler.exceptions 将为空,这意味着popupPanel 永远不会到达浏览器。重新渲染popupPanel 的后续请求将失败,因为在 DOM 中找不到该组件。

    对于要进行 ajax 更新的组件,它必须已经在浏览器的 DOM 中,这就是 ajax 的工作方式。因此解决方案是将弹出面板的内容包装在一个始终会呈现的组件中。

    除此之外,即使您的渲染正确,您的弹出窗口也只会放置在 DOM 中。您实际上需要在弹出窗口上调用show() 才能显示它

    然而,为了实现你想要的,更好的选择是

    1. 使用 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/>
      
    2. 从模态面板中取出渲染条件

    编辑:此外,弹出组件上的show 属性可以基于与oncomplete 属性相同的EL 条件

    【讨论】:

      猜你喜欢
      • 2013-03-15
      • 1970-01-01
      • 2015-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      相关资源
      最近更新 更多