【发布时间】:2011-11-05 12:12:32
【问题描述】:
我有一个方法,它接受 x 和 y 并将它们相加并返回结果。 现在第一个 InputText 将采用 x,第二个采用 Y。但我想将 X 和 Y 都传递给同一个方法,以便调用 public int addNumbers(int x, int y) 并返回它。知道怎么做吗? 我对 JSF 非常陌生 谢谢,
【问题讨论】:
我有一个方法,它接受 x 和 y 并将它们相加并返回结果。 现在第一个 InputText 将采用 x,第二个采用 Y。但我想将 X 和 Y 都传递给同一个方法,以便调用 public int addNumbers(int x, int y) 并返回它。知道怎么做吗? 我对 JSF 非常陌生 谢谢,
【问题讨论】:
有一个托管表单
public DataFormBean{
String number1;
String number2;
//setter getter + constructors
}
public ActionBean{
DataFormBean dataBean;
//setter + getter
public String add(){
// convert your number here to int and pass it to the method and set the result back to the baen
}
}
您需要声明托管 bean 并进行注入
<h:form>
<h:inputText value="#{dataBean.number1}" >
<h:inputText value="#{dataBean.number2}" >
<h:commandButton action="#{actionbean.add}" >
</h:form>
见
【讨论】: