【发布时间】:2016-12-26 15:43:57
【问题描述】:
我正在开发一个 JSF 应用程序 我有 2 个 selectOnemenu 控件和提交按钮。 如果两个字段的值相等,我需要禁用按钮
<h:selectOneMenu id="from" value="#{currencyBean.history.fromCurrency}" >
<f:selectItems value="#{currencyBean.currency}" var="c" itemValue="#{c}" itemLabel="#{c.name}"/>
</h:selectOneMenu>
<p:outputLabel for="to" value="to:" />
<h:selectOneMenu id="to" value="#{currencyBean.history.toCurrency}" >
<f:selectItems value="#{currencyBean.currency}" var="c" itemValue="#{c}" itemLabel="#{c.name}"/>
</h:selectOneMenu>
<p:commandButton id="calculateButton" value="Convert" update=":convert :historyPanel" onstart="PF('statusDialog').show()" onsuccess="PF('statusDialog').hide()" validateClient="true" ajax="true" action="#{currencyBean.Calculate()}" />
我尝试将 onchange 与 ajax 一起使用,但每次我更改一个下拉列表时,第二个下拉列表的值在 backbean 中变为空,因此我无法读取它。
这是我的豆豆
@Named(value = "currencyBean")
@RequestScoped
public class CurrencyBean implements Serializable {
/**
* Creates a new instance of CurrencyBean
*/
private History history;
private Currency currency;
private Date currentDate;
@Inject
private Loginbean loginBean;
private List<History> historyList;
public List<History> getHistoryList() {
int userId = loginBean.getUserId();
if (userId != -1) {
return new HistoryHelper().GetHistoryListByUser(userId);
}
return null;
}
public CurrencyBean() {
history = new History();
}
public History getHistory() {
return history;
}
public void setHistory(History history) {
this.history = history;
}
public Currency[] getCurrency() {
return Currency.values();
}
public Date getCurrentDate() {
return new Date();
}
public void Calculate() {
int userId = loginBean.getUserId();
if (userId != -1) {
new CurrencyClient().Convert(userId, this.history);
}
}
}
有什么线索吗?
【问题讨论】:
-
你能不能更精确一点,并准确输入你是如何实现 onchange 方法的?以及您的支持 bean 的外观,尤其是它的范围
-
我已经更新了我的问题以添加我的 backbean。关于 onchange 实现,我只是尝试在日志中写入 from 和 to 两个字段的值,但是如果我从字段更新,则 to 值为 null,如果我更新到字段,则 from 值为 null
-
这个 onchange 实现在哪里?在 selectOneMenu 中? onchange 属性中叫什么
标签: jsf primefaces selectonemenu