【发布时间】:2010-09-20 13:54:47
【问题描述】:
我最近一直在开发一些 JSF 应用程序,并且对 Web 组件 API 的不一致感到不安。
我注意到在服务器端代码中对 JSF 组件对象调用 .getValue() 或 .getSubmittedValue() 时会出现极其不可预测的行为。有时,当我在下拉列表框上调用 .getValue() 时,我注意到我得到的值是在我选择我的值之前的值(因此来自最后一页刷新的值),其中 .getSubmittedValue() 得到我是正确的值,例如:
UIInput name = new UIInput(); // This is the control I have in a bean.
public void submit(ActionEvent ae)
{
someMethod(name.getValue().toString()); // Retrieves the "old" value
someMethod(name.getSubmittedValue().toString()); // Retrieves the correct value
}
另外,我注意到在表单字段上调用 .getSubmittedValue() 有时会导致空指针异常,因为该值尚未在组件对象中实例化,在这种情况下,当我调用 .getValue() 时情况我得到正确的值,例如:
HtmlInputText name = new HtmlInputText(); // This is the control I have in a bean.
public void submit(ActionEvent ae)
{
someMethod(name.getValue().toString()); // Retrieves the correct value
someMethod(name.getSubmittedValue().toString()); // Throws NullPointerException
}
这只是 JSF 框架的一个“怪癖”,还是我只是错误地使用了 API COMPLETELY?对这两种方法的任何见解将不胜感激。干杯。
【问题讨论】:
-
您正在使用哪个 JSF 实现?这可能是一个具有特定风格的错误,而不是标准。
-
我正在使用 Infragistics NetAdvantage 组件,JSF 1.2。
标签: jsf