简体   繁体   English

JSF传递要在另一个页面中显示的列表

[英]JSF passing a list to be displayed in another page

Hi i am new to JSF an i am a bit lost. 嗨,我是JSF的新手,我有点迷路。 This what i want to do. 这是我想做的。 I have a page where i display a list of shows where every show has a list of representations. 我有一个页面,在该页面上我会显示一个节目列表,其中每个节目都有一个表示形式列表。 I want the user by clicking on a particular show to go a page where only the linked representations to the show are displayed. 我希望用户通过单击特定的节目进入到仅显示该节目的链接表示的页面。 Here are my current .xhtml pages and my two managed beans. 这是我当前的.xhtml页面和两个托管bean。 What they do right now is that they display all shows and all lists. 他们现在所做的是显示所有节目和所有列表。

@Entity
@Table(name = "SHOW_SPECTACLE")
public class Spectacle implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;

    @ElementCollection
    @CollectionTable(name = "T_TYPES_SPECTACLE")
    @Column(name = "TYPES_SPECTACLE")
    private List<String> typesSpectacle;

    @Column(name = "NOM_SPECTACLE")
    private String nomSpectacle;

    @Column(name = "DESCRIPTION")
    private String description;
    @Column(name = "LIEN_VIDEO")
    private String lienVideo; // type Blop
    @Column(name = "LIEN_IMAGE")
    private String lienImage;

    @OneToOne
    private Artiste artiste;
    @OneToMany(mappedBy = "spectacle")
    private List<Representation> representations;

}

public class Representation implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;
    @Column(name = "NB_BILLETS_DISPO")
    private Integer nbBilletsDispo;
    @Column(name = "PRIX")
    private Float prix;
    @Column(name = "NOM")
    private String nom;
    @Column(name = "ADRESSE")
    private String adresse;
    @Column(name = "DATE_DEBUT")
    @Temporal(TemporalType.DATE)
    private Date dateDebut;
    @Column(name = "DATE_FIN")
    @Temporal(TemporalType.DATE)
    private Date dateFin;
    @Column(name = "IS_ANNULATION")
    private Boolean isAnnulation;

    @OneToOne(mappedBy = "representation")
    private Salle salle;

    @ManyToOne
    private Spectacle spectacle;

}

The xhtml page sections that display all the the shows, i use in it some primefaces components 显示所有节目的xhtml页面部分,我在其中使用了一些primefaces组件

<h:form id="form">  

        <p:dataGrid var="spec" value="#{menuCtrl.spectacles}" columns="3"  
                    rows="12" paginator="true"  
                    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                    rowsPerPageTemplate="9,12,15">  

            <p:panel header="#{spec.nomSpectacle}" style="text-align:center">

                <h:panelGrid columns="1" style="width:100%"> 
                    <ui:param name="imgPath" value="images:#{spec.artiste.lienPhoto}.png" />
                    <p:graphicImage value="#{resource[imgPath]}" />  

                    <h:outputText value="#{spec.description}" />  

<!--                        <p:commandLink update=":form:carDetail" oncomplete="carDialog.show()" title="View Detail">  
                            <h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" />   
                            <f:setPropertyActionListener value="{spec}"   
                                                         target="{tableBean.selectedCar}" />  
                    </p:commandLink>  -->
                </h:panelGrid>  
            </p:panel>  

        </p:dataGrid> 
    </h:form>

edit here is the bean used 在这里编辑是使用的bean

    @ManagedBean(name = "menuCtrl")
@ApplicationScoped
public class MenuControleur extends AbstractControleur implements Serializable {
private static final Logger log = Logger.getLogger(ApplicationControleur.class);

// cache
private List<Spectacle> spectacles;
private List<Representation> representations;
private List<Artiste> artistes;


private List<Representation> representationsFiltrees;


@PostConstruct
public void init() {
    // instanciation couche [métier]
    super.initStubsPresentation();

    this.spectacles = this.stubsDaoPresentation.getAllSpectacle();
    this.representations = this.stubsDaoPresentation.getAllRepresentation();
    this.artistes = this.stubsDaoPresentation.getAllArtistes(); 

    log.info("sonar source Spectacle 1: " + this.spectacles);
    log.info("sonar source Representation 1: " + this.representations);
    log.info("sonar source Artiste 1: " + this.artistes);
}    

public List<Representation> getRepresentationsFiltrees() {
    return representationsFiltrees;
}

public void setRepresentationsFiltrees(List<Representation> representationsFiltrees) {
    this.representationsFiltrees = representationsFiltrees;
}



public String doHomme(){
    return "eticket.index";
}

public String doCart(){
    return "eticket.pageCart";
}

public String doShow(){
    return "eticket.pageShows";
}

/**
 * Creates a new instance of MenuControleur
 */
public MenuControleur() {  }

public List<Spectacle> getSpectacles() {
    return spectacles;
}

public void setSpectacles(List<Spectacle> spectacles) {
    this.spectacles = spectacles;
}

public List<Representation> getRepresentations() {
    return representations;
}

public void setRepresentations(List<Representation> representations) {
    this.representations = representations;
}

public List<Artiste> getArtistes() {
    return artistes;
}

public void setArtistes(List<Artiste> artistes) {
    this.artistes = artistes;
}    

} }

You can add a 您可以添加一个

`<h:link value="Second Page" outcome="secondpage" >
    <f:param name="id" value="#{bean.id}" />
</h:link>

` `

or <a href="secondpage.jsf?id=#{bean.id}">Second Page</a> in your first page <a href="secondpage.jsf?id=#{bean.id}">Second Page</a>

You need something like this in the bean for your second page 您在第二页的Bean中需要这样的东西

@ManagedBean("bean2")
public class SecondPageBean {

  @ManagedProperty(value = "#{param.id}")
  private String id;
  private String name;

  @PostConstruct    
  public String init() {
     // initialieMySecondPageBasedOnIdFromFirstPage(id);
  }
}

You can also do this in your secondpage xhtml to replace @ManagedProperty(value = "#{param.id}") , 您也可以在第二页xhtml中执行此操作,以替换@ManagedProperty(value = "#{param.id}")

<f:metadata>
    <f:viewParam name="id" value="#{bean.id}" />
</f:metadata>

However if you want to share the object/state between the two consecutive requests then have a look into Flash scope. 但是,如果要在两个连续的请求之间共享对象/状态,请查看Flash范围。

Understand Flash Scope in JSF2 了解JSF2中的Flash作用域

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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