私は次の問題を抱えています:ボタンからjavaメソッドを呼び出すと、このメソッドはこの同じページにinputTextの現在の値を持ちます、これを行うことができますか?
4 に答える
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とメソッドを呼び出す
value
View以上のスコープ(例value="#{viewScope.Bean.field}"
)を持つマネージドBeanのフィールドへのEL参照を使用して、inputTextの属性を指定します。
private String field;
public String getField(){
return field;
};
public void setField(String field){
this.field = field;
};
次に、同じBean内のハンドラーメソッドへの参照を使用してactionListener
onを指定します。この方法でのアクセス:commandButton
actionListener="#{viewScope.Bean.handleButton}"
field
public void handleButton(ActionEvent event){
System.out.println('Input field content: ' + getField());
};
何を求めているのかわかりにくいですが、尋ねようとしている場合:ボタンをクリックすると、ボタンがバッキングJava Beanのメソッドを呼び出し、ADFFacesページの入力テキストフィールドの値にアクセスするようにします。 、答えはイエスです。入力テキストフィールドにBindingプロパティを設定し、ボタンにメソッド呼び出しを追加する必要があります。ボタンのActionListenerプロパティを使用し、actionlistenerメソッドを使用してバッキングBeanを指定または作成します。次に、入力テキストフィールドのバインディングプロパティを設定します。バッキングBeanにはテキストフィールドのget/setメソッドが必要であり、それらを使用してテキストフィールドへの参照を取得し、get / setValue()メソッドを呼び出すことができます。
了解した)
<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();
}