2009-06-17 10 views
2

私の小さなプログラムで問題が発見されましたが、できるだけこの問題を解決するためのヒントやアドバイスがありますか? 。要求スコープ付きBeanの値に基づいてレンダリングされたときにフォームを送信する方法

リクエストスコープにあるbean testBeanがあります。それには、次のものが含まれています

public class testBean { 

private boolean internal = false; 
private String input = ""; 

public String internalTrue() { 
    System.out.println("Set internal true"); 
    setInternal(true); 
    return null; 
} 
public String submitForm() { 
    System.out.println(""); 
    return null; 
} 
public boolean isInternal() { 
    return internal; 
} 
public void setInternal(boolean internal) { 
    this.internal = internal; 
} 
public String getInput() { 
    return input; 
} 
public void setInput(String input) { 
    this.input = input; 
} 

}

マイファイルwelcomeJSF.jspはこれを含んでいます

<f:view> 
     <h:form> 
      <h:commandButton value="Set internal true" action="#{testBean.internalTrue}" /> 
     </h:form> 
     <h:panelGrid columns="1" rendered="#{testBean.internal}"> 
      <h:form> 
       <h:outputText value="JavaServer Faces" /><h:inputText value="#{testBean.input}" /> 
       <h:commandButton value="Go" action="#{testBean.submitForm}" /> 
      </h:form> 
     </h:panelGrid> 
    </f:view> 

私はImが「真の内部設定」ボタンを提示するアプリケーションを実行すると。私はそれをクリックして、私はボタン "行く"があるフォームを提示した。 "Go"をクリックしてもBean内のメソッドはトリガされません。実際にはフィールドが実際にサーバー上でレンダリングされていないため、メソッドが実行されません。これにスマートな解決策はありますか?

事前に、お時間をいただきありがとうございます。そのレンダリング属性は常にREQUEST値を適用フェーズ中にに評価されるため、パネルの

答えて

2

子どもたちは、入力をデコードすることはありません。これは、セキュリティ上の観点からすると分かりやすいことです。あなたができる

alt text http://www.ibm.com/developerworks/java/library/j-jsf2/basic-lifecycle.gif


ことの一つは、JSFコンポーネントがビューの寿命のために状態を維持しているという事実を利用しています。

新しいbean:

public class TestBean { 

    private String input = null; 
    private UIComponent panel; 

    public String internalTrue() { 
    panel.setRendered(true); 
    return null; 
    } 

    public String submitForm() { 
    panel.setRendered(false); 
    System.out.println("submitForm"); 
    return null; 
    } 

    public UIComponent getPanel() { return panel; } 
    public void setPanel(UIComponent panel) { this.panel = panel; } 

    public String getInput() { return input; } 
    public void setInput(String input) { this.input = input; } 

} 

Beanにバインドされた新しいビュー:panelGridbinding属性を使用

<f:view> 
    <h:form> 
     <h:commandButton value="Set internal true" 
     action="#{testBean.internalTrue}" /> 
    </h:form> 
    <h:panelGrid binding="#{testBean.panel}" columns="1" 
     rendered="false"> 
     <h:form> 
     <h:outputText value="JavaServer Faces" /> 
     <h:inputText value="#{testBean.input}" /> 
     <h:commandButton value="Go" action="#{testBean.submitForm}" /> 
     </h:form> 
    </h:panelGrid> 
    </f:view> 

setPanelが時にビューと呼ばれるようになります作成/復元されます。


あなたはどのように実装者および/または(順番にjavax.faces.STATE_SAVING_METHOD初期化パラメータによって影響を受ける可能性がある)要求間のライブラリのStateManagerストアビューに応じて行うにはいくつかのテストを持っている場合があります。ビューはフォームの非表示フィールド、ビューID(複数のブラウザウィンドウとの衝突を引き起こす可能性がある)、GETまたはJSFナビゲーションによって作成された一意のIDにキーされたセッション、またはいくつかの完全なカスタムメカニズム。フレームワークのプラガブルな性質は汎用性に富んでいますが、この場合、実装がどのように動作するかを再確認する必要があります。

+0

私のためにそれをクリアしてくれてありがとう!非常に良い答え –

関連する問題