2012-04-01 14 views
0

私はバッキングビーン、Foo、クライアント、リクエスト、レスポンスを持つテンプレートを持っています。クライアントは冗長であり、ただ1つのクライアントが必要です。hello world faceslets 2.0 navigation

クライアント:私は、それ自体で、OKだと思います

[email protected]:~$ 
[email protected]:~$ cat NetBeansProjects/NNTPjsf/web/foo/request.xhtml 
<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" 
       template="./template.xhtml" 
       xmlns:h="http://java.sun.com/jsf/html"> 

    <ui:define name="left"> 

     <h:form> 
      <h:inputText size="2" maxlength="50" value="#{foo.bar}" /> 
      <h:commandButton id="submit" value="submit" action="response" /> 
     </h:form> 
    </ui:define> 

    <ui:define name="content"> 
     <h:outputText value="#{foo.bar}"></h:outputText> 
    </ui:define> 

</ui:composition> 
[email protected]:~$ 
[email protected]:~$ cat NetBeansProjects/NNTPjsf/web/foo/response.xhtml 
<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" 
       template="./template.xhtml" 
       xmlns:h="http://java.sun.com/jsf/html"> 

    <ui:define name="left"> 

     <h:form> 
      <h:inputText size="2" maxlength="50" value="#{foo.bar}" /> 
      <h:commandButton id="submit" value="submit" action="response" /> 
     </h:form> 
    </ui:define> 

    <ui:define name="content"> 
     <h:outputText value="#{foo.bar}"></h:outputText> 
    </ui:define> 

</ui:composition> 
[email protected]:~$ 

バッキングBean:

package guessNumber; 

import java.io.Serializable; 
import javax.enterprise.context.SessionScoped; 
import javax.faces.context.FacesContext; 
import javax.inject.Named; 
import javax.servlet.http.HttpSession; 

@Named 
@SessionScoped 
public class Foo implements Serializable { 

    private String bar = "bar"; 
    private String response = "response"; 

    public Foo() { 
    } 

    /** 
    * @return the bar 
    */ 
    public String getBar() { 
     return bar; 
    } 

    /** 
    * @param bar the bar to set 
    */ 
    public void setBar(String bar) { 
     this.bar = bar; 
    } 

    /** 
    * @return the response 
    */ 
    public String getResponse() { 
     FacesContext context = FacesContext.getCurrentInstance(); 
     HttpSession session = (HttpSession) context.getExternalContext().getSession(false); 
     session.invalidate(); 
     response = "hmm"; 
     return response; 
    } 

    /** 
    * @param response the response to set 
    */ 
    public void setResponse(String response) { 
     this.response = response; 
    } 
} 

私は希望だけで単一のクライアント、REQUEST_RESPONSEか何かです。テキスト入力フォームは左に、結果は右にとどまるようにします。それはコンポジションタグで行われますか?または、2つのサブクライアントを持つ第3の「一般クライアント」ですか?アクションメソッドでは

<h:commandButton id="submit" value="submit" action="#{foo.doAction}" /> 

応答を設定します:

答えて

2

あなたはバッキングBean内のアクションメソッドを呼び出すための要求ページでコマンドボタンを変更する必要が

public String doAction() { 
    response = "hmm"; 
    return "response"; 
} 

の戻り値アクションメソッドは/response.xhtmlページにナビゲートします。

しかし、2ページは必要ありません。

<ui:define name="content"> 
    <h:outputText value="#{foo.bar}"></h:outputText> 
    <h:outputText value="#{foo.response}"></h:outputText> 
</ui:define> 
+0

わずか2つのヒント:右側に表示することができます次に

public String doAction() { response = "hmm"; return null; } 

バーと応答のための変更された値を:あなたは、現在の(要求)ページをリロードするアクションメソッドからnullを返すことができます。同じページにいたいなら、あなたのアクションメソッドを 'void doAction(){}'として定義することができます。また、この場合、 ''は必要ないかもしれません。 ELを直接Faceletに置くことができます。これが役に立ったと思っています;) –

+0

答えは大盛りですが、私は数時間後にそれを試してみて、ここに戻ってきます。ありがとう! – Thufir

+0

ありがとう、皆さん。 – Thufir