2013-03-11 88 views
0

嗨,我是新來的JSF我有點失落。這是我想要做的。 我有一個頁面,其中顯示每個節目都有一個表示列表的節目列表。我希望用戶通過點擊某個特定的節目來進入只顯示節目的鏈接表示的頁面。這裏是我當前的.xhtml頁面和我的兩個託管的bean。他們現在所做的是顯示所有節目和所有列表。JSF通過一個列表顯示在另一個頁面

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

} 

是顯示所有的顯示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> 

編輯這裏是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; 
}  

}

+0

,我建議你看看[此鏈接](http://balusc.blogspot.com/2006/06/communication-in-jsf.html),或在[這一個](HTTP ://balusc.blogspot.com/2011/09/communication-in-jsf-20.html)如果您使用的是JSF2。另外,請注意,您目前顯示的不是託管bean的代碼,而是您實體的代碼。 – Gamb 2013-03-11 19:29:06

+0

但是,不能回答你如何從一個頁面到另一個頁面。 – user2133558 2013-03-11 20:04:02

+0

您提供的xhtml與您想要實現的功能不匹配。 – 2013-03-11 20:09:22

回答

0

您可以添加一個

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

`

或在您的第一頁<a href="secondpage.jsf?id=#{bean.id}">Second Page</a>

您需要在豆你的第二個頁面是這樣的

@ManagedBean("bean2") 
public class SecondPageBean { 

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

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

你也可以做到這一點在你的secondpage XHTML更換@ManagedProperty(value = "#{param.id}")

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

但是,如果你wan t在兩個連續請求之間共享對象/狀態,然後查看Flash範圍。

Understand Flash Scope in JSF2

+0

嗨,謝謝你的回覆。我會查找您的示例,但我試圖模擬@ Xtrem-Biker給出的示例,這是我正在嘗試執行的操作。 我將放置一個命令按鈕,它將調用MenuControlleur中的一個新方法,該方法必須將spec.representations放入新列表屬性中,並將用戶重定向到rep頁面。重定向正在工作,但未通過列表。 – user2133558 2013-03-11 21:45:23

+0

RequestScope bean不會在重定向之間持續存在,但正如我在您的示例中看到的那樣,您正在使用applicationcoped bean,因此您應該能夠在任何頁面上獲取並存儲該bean的值。 – 2013-03-11 23:27:49

相關問題