値をBeanプロパティにバインドせずに、入力テキストフィールド値をBeanメソッドに渡すことはできますか?
<h:inputText value="#{myBean.myProperty}" />
<h:commandButton value="Test" action="#{myBean.execute()} />
一時的に保存せずにこれを行うことはできます#{myBean.myProperty}
か?
値をBeanプロパティにバインドせずに、入力テキストフィールド値をBeanメソッドに渡すことはできますか?
<h:inputText value="#{myBean.myProperty}" />
<h:commandButton value="Test" action="#{myBean.execute()} />
一時的に保存せずにこれを行うことはできます#{myBean.myProperty}
か?
UIInput
ビューに関してコンポーネントをバインドし、UIInput#getValue()
メソッド引数としてその値を渡すために使用します。
<h:inputText binding="#{input1}" />
<h:commandButton value="Test" action="#{myBean.execute(input1.value)}" />
と
public void execute(String value) {
// ...
}
値はこの方法ですでに変換され、通常のJSFの方法で検証されていることに注意してください。
リクエストを取得し、プレーンなJava EE ServletRequest#getParameterを使用することで、フォームのパラメーターを回復できます。この方法を使用するときは、コンポーネントのIDと名前を設定することを忘れないでください。
<h:form id="myForm">
<h:inputText id="txtProperty" /> <!-- no binding here -->
<input type="text" id="txtAnotherProperty" name="txtAnotherProperty" />
<h:commandButton value="Test" action="#{myBean.execute()} />
</h:form>
マネージドBean:
@ManagedBean
@RequestScoped
public class MyBean {
public void execute() {
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
String txtProperty = request.getParameter("myForm:txtProperty");
//note the difference when getting the parameter
String txtAnotherProperty= request.getParameter("txtAnotherProperty");
//use the value in txtProperty as you want...
//Note: don't use System.out.println in production, use a logger instead
System.out.println(txtProperty);
System.out.println(txtAnotherProperty);
}
}
詳細情報のある別のスレッド: