2016-05-24 28 views
0

這裏是我的testBean就如何在commandButton執行後重新加載outputText內容?

@ManagedBean (name="testBean") 
@SessionScoped 

public class TestBean implements Serializable { 
    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 
    private int testParameter; 

    public int getTestParameter() { 
     return testParameter; 
    } 
    public void setTestParameter(int testParameter) { 
     this.testParameter = testParameter; 
    }  
} 

這裏是我的Text.xhtml

<h:commandButton value="Click Me" action="#{testBean.setTestParameter(123456)}"/> 
      <h:outputText value="#{testBean.testParameter}" id="outputTestId"/> 

當我點擊該按鈕,<h:output沒有得到重新加載,仍然顯示零0(默認爲int)。我如何重新加載它?

爲什麼不重新加載?我指定@SessionScoped

回答

0

參考Information to provide when asking JSF questions

你缺少一個H:形式。

<h:form> 
     <h:commandButton value="Click Me" 
      action="#{testBean.setTestParameter(123456)}" /> 
     <h:outputText value="#{testBean.testParameter}" id="outputTestId" /> 
    </h:form> 
+0

我有我的形式並沒有把它放在我有問題遺憾 – Emily

+0

請提供您完整的XHTML文件和細節JSF實現罐子。附帶的xhtml正在使用Tomcat 7處理JSF 2.2 mojarra。 – Ravi

+0

@ravi:op應該發佈[mcve],而不是完整的xhtml – Kukeltje

相關問題