【问题标题】:Show bean values in rich:popupPanel在 rich:popupPanel 中显示 bean 值
【发布时间】:2013-11-18 21:15:25
【问题描述】:

我有一个 rich:dataTable,并且喜欢在用户单击详细信息按钮时在 rich:popupPanel 中显示每一行的详细信息。

我是这样做的

                <h:panelGrid columns="3" columnClasses="titleCell">
                    <h:form id="form">
                        <rich:dataScroller for="table" maxPages="5" />
                        <rich:dataTable value="#{tournSelectionBean.tournaments}"
                            var="tourn" id="table" rows="10">
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Name" />
                                </f:facet>
                                <h:outputText value="#{tourn.name}" />
                            </rich:column>
                            <rich:column>
                            <a4j:commandButton value="Detail"
                                action="#{tournSelectionBean.setCurrentTournament(tourn)}"
                                render=":detailpopup"
                                oncomplete="#{rich:component('detailpopup')}.show();" />
                        </rich:column>
                        </rich:dataTable>
                        <rich:dataScroller for="table" maxPages="5" />
                    </h:form>
                </h:panelGrid>

                <rich:popupPanel id="detailpopup" modal="true" resizeable="false"
                    autosized="true">
                    <f:facet name="header">
                        <h:outputText value="#{tournSelectionBean.currentTournament.name}" />
                    </f:facet>
                    <f:facet name="controls">
                        <h:outputLink value="#"
                            onclick="#{rich:component('detailpopup')}.hide(); return false;">

                        </h:outputLink>
                    </f:facet>
                    <h:panelGrid columns="2" columnClasses="titleCell">

                        <h:outputLabel value="City" />
                        <h:outputLabel
                            value="#{tournSelectionBean.currentTournament.city}" />

                    </h:panelGrid>
                    <a href="#" onclick="#{rich:component('detailpopup')}.hide()">Close</a>
                </rich:popupPanel>

setPropertyActionListener 正确设置了 ID,弹出窗口按预期打开。但是弹出窗口显示了创建视图时 bean 中的锦标赛的详细信息(而不是由 propertyactionlistner 设置的那个)。

我怎样才能做到这一点?

编辑:更新了上面的代码并添加了 Bean:

@Named("tournSelectionBean")
@ViewScoped
public class TournamentSelectionBean implements Serializable {

  @EJB
  private TournamentControllerInterface tournamentController;

  private List<Tournament> tournaments;

  private Tournament currentTournament;

  @PostConstruct
  public void init() {
    tournaments = tournamentController.loadTournaments(true, false);
  }

  /**
   * @return the tournaments
   */
  public List<Tournament> getTournaments() {
    return tournaments;
  }

  /**
   * @param tournaments
   *          the tournaments to set
   */
  public void setTournaments(List<Tournament> tournaments) {
    this.tournaments = tournaments;
  }

  /**
   * @return the currentTournament
   */
  public Tournament getCurrentTournament() {
    return currentTournament;
  }

  /**
   * @param currentTournament the currentTournament to set
   */
  public void setCurrentTournament(Tournament currentTournament) {
    this.currentTournament = currentTournament;
  }

}

【问题讨论】:

    标签: java jsf richfaces


    【解决方案1】:

    你需要告诉 JSF 在你打开它之前重新渲染弹出的 html:

    <a4j:commandButton value="Detail" 
        action="#{tournSelectionBean.setCurrentTournament(tourn)}"
        render=":detailpopup"
        oncomplete="#{rich:component('detailpopup')}.show();" />
    

    请注意:如果您在 popupPanel 中有 &lt;h:form&gt;,则在重新渲染完整的弹出窗口时可能会遇到问题。将所有内容放在表单内的&lt;h:panelGroup&gt; 中,然后重新渲染那个。

    【讨论】:

    • 我更改了代码(参见编辑后的代码)。它仍然不起作用。但是在调试模式下,我看到 bean 在使用操作设置后被重新创建。为什么会这样?我也尝试过 SessionScope 但有相同的行为。 :detailpopup 中的 ":" 是什么意思?
    • @user2558023 您使用哪个范围?请注意,您需要 import javax.faces.view.ViewScoped 否则您的 bean 将表现得像一个请求范围的。 ":" 告诉 JSF 搜索 h:form 之外的 id(对于 Richfaces 不是绝对必要的)。
    • 我不小心使用了 javax.faces.bean.ViewScoped。但现在我不得不切换到@ConversationScoped,因为 ViewScoped 不适用于 CDI。现在一切正常。 THX
    • @user2558023 是的,@javax.faces.view.ViewScoped 仅适用于 JSF-2.2(但它确实适用于 CDI)。
    • 是的,你是对的。它适用于 Wildfly 8.0。 Wildfly 8 使用 jsf 2.2 吗?如何查看使用的是哪个版本?
    猜你喜欢
    • 2015-12-13
    • 1970-01-01
    • 2012-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    相关资源
    最近更新 更多