简体   繁体   中英

Show bean values in rich:popupPanel

I have a rich:dataTable and like to show details to each row in a rich:popupPanel when the user clicks on the detail button.

I do this like this

                <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>

The setPropertyActionListener sets the ID correctly and the popup opens as expected. But the popup shows the details of the tournament that was in the bean when the view was created (and not the one that was set by the propertyactionlistner).

How can I achieve this?

EDIT: Updated above code and added 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;
  }

}

You need to tell JSF to re-render the popup html before you open it:

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

Be careful: if you have a <h:form> inside the popupPanel, you may have issues when you re-render the complete popup. Put everything in a <h:panelGroup> inside the form, then re-render that one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM