2011-04-25 93 views

回答

2

繼續JSF。這是你的要求會是什麼樣子:

視圖(test.xhtml

<!DOCTYPE html> 
<html lang="en" 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
> 
    <h:head> 
     <title>JSF Hello World</title> 
    </h:head> 
    <h:body> 
     <h:form> 
      <h:commandButton value="Hey" action="#{bean.hey}"> 
       <f:ajax render=":result" /> 
      </h:commandButton> 
     </h:form> 
     <h:outputText id="result" value="#{bean.result}" /> 
    </h:body> 
</html> 

模型(Bean.java

@ManagedBean 
@RequestScoped 
public class Bean { 

    private String result; 

    public void hey() { 
     result = "Hello World!"; 
    } 

    public String getResult() { 
     return result; 
    } 

} 

就是這樣。

0

有多種可能的方法來做到這一點。

  • JSF EL做得很好。
  • 你可以使用DWR從調用簡單的javascript調用來調用bean的方法,它會創建一個jj請求來調用服務器上的bean的方法。