1

プログラムで表示する必要がある Bean のフィールドがいくつかあります。次のようなものです:

         HtmlPanelGrid panel = new HtmlPanelGrid();
         panel.setColumns(4);

         HtmlOutputLabel fieldOut = new HtmlOutputLabel();
         fieldOut.setId("fieldOutId");
         fieldOut.setValue("name");
         panel.getChildren().add(fieldOut);
         HtmlInputText fieldIn = new HtmlInputText();
         fieldIn.setId("fieldInId");
         fieldIn.setPartialSubmit(true);
         fieldIn.setValueExpression(
          "field", UtilFaces.createValueExpression("#{newElementBean.fieldName}",String.class));

         panel.getChildren().add(fieldIn); 
         mainForm.getChildren().add(panel);

newElements.xhtml で、次のように mainForm にバインドされるフォームを定義しました。

    <ice:form binding="#{newElementBean.mainForm}">
  <ice:inputText id="ANOTHERFIELD" value="#{newElementBean.anotherField}"/>
  <ice:commandButton  action="#{newElementBean.save}"  value="Save"/>
</ice:form>

保存ボタンをクリックして次のビューに移動すると、フィールド「ANOTHERFIELD」は Bean から値を取得して正しく表示されますが、動的に生成されたフィールドは空と表示されます。バッキング Bean の値も null です。バッキング Bean で作成した がValueExpression機能していないようです。HtmlInputTextMojarra 2.1.17 で Icefaces 3.3 を使用しています。

これはどのように発生し、どうすれば解決できますか?

4

1 に答える 1

2

私はそれを解決しました。私は2つの間違いを犯しました:

  1. 適切なsetValueExpression呼び出しは次のようになります。

    fieldIn.setValueExpression("value", UtilFaces.createValueExpression("#newElementBean.fieldName}");
    

    "field1"の代わりに を第 1 引数として誤って使用していまし"value"た。

  2. これは質問には表示されませんが、私のcreateValueExpression()ヘルパー メソッドも間違っていました。以下は私のために働いています:

    public static ValueExpression createValueExpression(String expression) {
        Application app = FacesContext.getCurrentInstance().getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = FacesContext.getCurrentInstance().getELContext();
        return elFactory.createValueExpression(elContext, expression, Object.class);
    }
    
于 2013-09-04T06:10:14.307 に答える