JSF 无法获取带参数的方法返回的值的 属性
JSF can't get property of a value returned by a method with parameters
我一直被一个问题所困扰,该问题涉及允许 Double
类型的输入字段为 null 或其他值。
由于我使用的是自动生成的代码,所以我无法触及对象的 get/set 方法。此外,我无法修改服务器参数,例如 -Dorg.apache.el.parser.COERCE_TO_ZERO
.
我最近的解决方案是为自动生成的对象制作一个包装器对象,它处理 String
而不是 Double
。在这里:
public class WrapperType {
private AUTO_GENERATED_OBJECT autogen;
public WrapperType(AUTO_GENERATED_OBJECT autogen) {
this.autogen = autogen;
}
public String getOperation() {
if (autogen.getOperation() == null) {
return null;
}
return autogen.getOperation() + "";
}
public void setOperation(String value) {
if (value == null || value.isEmpty()) {
autogen.setOperation(null);
} else {
autogen.setOperation(Double.valueOf(value));
}
}
}
所以我所要做的就是,不要在我的自动生成的对象上调用 get/set,而是在等效包装器上调用 get/set,这可以通过以下方式获得:
public WrapperType convertVar(AUTO_GENERATED_OBJECT autogen) {
return new WrapperType(autogen);
}
然后在需要的地方参考一下:
<p:inputText value="#{bean.convertVar(_var).operation}" />
除了这不起作用。我收到一个错误:
javax.el.PropertyNotFoundException: /operation/collections/tabs/page.xhtml The class 'MyClass$Proxy$_$$_WeldClientProxy' does not have the property 'convertVar'.
有人对如何解决此问题或克服我对空值和数值的要求有任何想法吗?
看看这个。只需使用 @WebListener 修改 属性 并获取空值而不是零值。
coerce to zero
我一直被一个问题所困扰,该问题涉及允许 Double
类型的输入字段为 null 或其他值。
由于我使用的是自动生成的代码,所以我无法触及对象的 get/set 方法。此外,我无法修改服务器参数,例如 -Dorg.apache.el.parser.COERCE_TO_ZERO
.
我最近的解决方案是为自动生成的对象制作一个包装器对象,它处理 String
而不是 Double
。在这里:
public class WrapperType {
private AUTO_GENERATED_OBJECT autogen;
public WrapperType(AUTO_GENERATED_OBJECT autogen) {
this.autogen = autogen;
}
public String getOperation() {
if (autogen.getOperation() == null) {
return null;
}
return autogen.getOperation() + "";
}
public void setOperation(String value) {
if (value == null || value.isEmpty()) {
autogen.setOperation(null);
} else {
autogen.setOperation(Double.valueOf(value));
}
}
}
所以我所要做的就是,不要在我的自动生成的对象上调用 get/set,而是在等效包装器上调用 get/set,这可以通过以下方式获得:
public WrapperType convertVar(AUTO_GENERATED_OBJECT autogen) {
return new WrapperType(autogen);
}
然后在需要的地方参考一下:
<p:inputText value="#{bean.convertVar(_var).operation}" />
除了这不起作用。我收到一个错误:
javax.el.PropertyNotFoundException: /operation/collections/tabs/page.xhtml The class 'MyClass$Proxy$_$$_WeldClientProxy' does not have the property 'convertVar'.
有人对如何解决此问题或克服我对空值和数值的要求有任何想法吗?
看看这个。只需使用 @WebListener 修改 属性 并获取空值而不是零值。
coerce to zero