2013-06-03 83 views
0

我有這樣的代碼:PrimeFaces的commandButton沒有導航

Add.xhtml:

<h:form id="nouv"> 
    <h:panelGrid columns="2"> 
     <h:outputText value="Nom:"></h:outputText> 
     <p:inputText value="#{ddeBean.nom}"></p:inputText> 
     <p:commandButton id="save" 
       value="ajouter"  
       update=":nouv:btn"       
       actionListener="#{ddeBean.ajouter}"> 
     </p:commandButton> 

     <p:outputPanel id="btn"> 
      <h:outputText rendered="#{ddeBean.created}" value="#{ddeBean.message}"/> 
      <p:commandButton id="btn_cr" value="add" rendered="#{ddeBean.created}" 
        action="pool.xhtml?faces-redirect=true"> 
      </p:commandButton> 
     </p:outputPanel> 
    </h:panelGrid> 
</h:form> 

ddeBean.java:

@ManagedBean(name = "ddeBean") 
@RequestScoped 
public class DemandeBean implements Serializable{ 
    ddeDAO dao = new ddeDaoImpl(); 
    private String nom; 
    public String message = ""; 
    private boolean created = false; 

    public void test(ActionEvent event){ 
     Demande p = new Demande(); 
     p.setDde(this.nom); 
     dao.Nouveau_dde(p); 
     created = true; 
     this.setMessage("saved!"); 
    } 
} 

當我單擊命令Ajouter消息的命令按鈕將顯示,但命令按鈕不會重定向到pool.xhtml

回答

0

當你點擊按鈕添加,豆被重建和值#{ddeBean.created}然後重新初始化爲false使按鍵沒有得到之前操作發生的位置呈現。

要解決該問題,您需要將bean的範圍更改爲@ViewScoped

你也應該確保通過

public void ajouter(ActionEvent event){ 

更換

public void test(ActionEvent event){ 

,如果你想你的按鈕正常工作。

另一種解決方案

由於您使用PrimeFaces,您可以顯示由JavaScript您的按鈕:

<p:commandButton id="save" 
    value="ajouter"  
    oncomplete="panel-create.show();"       
    actionListener="#{ddeBean.ajouter}"> 
</p:commandButton> 

<p:outputPanel id="btn" style="display: none;" widgetVar="panel-create"> 
    <h:outputText value="#{ddeBean.message}"/> 
    <p:commandButton id="btn_cr" value="add" 
     action="pool.xhtml?faces-redirect=true"> 
    </p:commandButton> 
</p:outputPanel> 

注意oncomplete屬性上p:commandButton,在p:panelrenderedwidgetVar屬性屬性已刪除。

+0

好的我會嘗試 – joice

+0

當我將範圍更改爲@ViewScoped時出現錯誤,我的xhtm頁面不再顯示 – joice

+0

什麼錯誤?你清理/重新編譯/重新部署了嗎? –

相關問題