1

私は次の問題を抱えています:ボタンからjavaメソッドを呼び出すと、このメソッドはこの同じページにinputTextの現在の値を持ちます、これを行うことができますか?

4

4 に答える 4

6

1.マネージドBeanを作成します。2.このコードを使用してメソッドを定義します::

FacesContext facesContext = FacesContext.getCurrentInstance();
    UIViewRoot root = facesContext.getViewRoot();
    RichInputText inputText = (RichInputText)root.findComponent("it1");
    String val=inputText.getValue();

where it1 is id for your input text

3.ボタンのプロパティウィンドウからボタンのアクションリスナーを選択します。4.マネージドBeanとメソッドを呼び出す

于 2012-07-17T12:40:49.950 に答える
3

valueView以上のスコープ(例value="#{viewScope.Bean.field}")を持つマネージドBeanのフィールドへのEL参照を使用して、inputTextの属性を指定します。

private String field;
public String getField(){ 
    return field; 
};
public void setField(String field){
    this.field = field;
};

次に、同じBean内のハンドラーメソッドへの参照を使用してactionListeneronを指定します。この方法でのアクセス:commandButtonactionListener="#{viewScope.Bean.handleButton}"field

public void handleButton(ActionEvent event){
    System.out.println('Input field content: ' + getField());
}; 
于 2012-07-23T09:34:46.700 に答える
0

何を求めているのかわかりにくいですが、尋ねようとしている場合:ボタンをクリックすると、ボタンがバッキングJava Beanのメソッドを呼び出し、ADFFacesページの入力テキストフィールドの値にアクセスするようにします。 、答えはイエスです。入力テキストフィールドにBindingプロパティを設定し、ボタンにメソッド呼び出しを追加する必要があります。ボタンのActionListenerプロパティを使用し、actionlistenerメソッドを使用してバッキングBeanを指定または作成します。次に、入力テキストフィールドのバインディングプロパティを設定します。バッキングBeanにはテキストフィールドのget/setメソッドが必要であり、それらを使用してテキストフィールドへの参照を取得し、get / setValue()メソッドを呼び出すことができます。

于 2012-07-06T15:52:26.603 に答える
0

了解した)

  <af:panelFormLayout id="pfl1">
      <f:facet name="footer">
        <af:commandButton text="отправить" id="cb1" 
                          actionListener="#{inBean.doSave}" partialSubmit="true"/>
      </f:facet>
      <af:inputText label="Ввести данные:" value="#{inBean.myParam}"  id="it1"/>
      <af:outputText value="#{inBean.myParam}" id="ot1" partialTriggers="cb1"/>
    </af:panelFormLayout>

    public void doSave(ActionEvent actionEvent) {
   // ActionResponse response = (ActionResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
   // response.setRenderParameter("myParam", myParam);
    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot root = context.getViewRoot();
    RichInputText inputText = (RichInputText) root.findComponent("it1");
    myParam = (String)inputText.getValue();
}
于 2016-12-05T05:14:21.800 に答える