如何在Java中将参数值传递给Conversion类? [英] How do I pass a parameter value to a Conversion class in java?
问题描述
我正在尝试将值传递给JSF/SEAM中的转换类
public class ValueConverter implements Converter {
public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
if (StringUtils.isNotBlank(value)) {
// logic etc here.
我的xhtml是:
<f:converter converterId="ValueConverter">
<f:attribute name="theMaxOrderSize" id="maxorder" value="#{_cartItem.item.maxOrderSize}"/>
</f:converter>
如何在Java中将参数值传递给Conversion类?我是从错误开始吗?我认为我正在使用JSF 1.2.
Bhesh是完全正确的.您应该在 Validator
中进行验证工作. /p>
对于具体问题,将 使用 (其中 您可以将其强制转换为 I am trying to pass a value to a conversion class in JSF/SEAM My xhtml is: How do I pass a parameter value to a Conversion class in java? Am I starting off wrong? I am using JSF 1.2 I think.. Bhesh is entirely right. You should be doing the validating job inside a As to the concrete problem, move the with (where You can cast it to 这篇关于如何在Java中将参数值传递给Conversion类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!<f:attribute>
从<f:converter>
中移出(如果您正在听我们的话,则从<f:validator>
移至)输入组件,然后使用Object theMaxOrderSize = component.getAttributes().get("theMaxOrderSize");
// ...
component
是validate()
方法的UIComponent
自变量,它表示父输入组件) Integer
或#{_cartItem.item.maxOrderSize}
表示的任何对象类型.public class ValueConverter implements Converter {
public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
if (StringUtils.isNotBlank(value)) {
// logic etc here.
<f:converter converterId="ValueConverter">
<f:attribute name="theMaxOrderSize" id="maxorder" value="#{_cartItem.item.maxOrderSize}"/>
</f:converter>
Validator
.<f:attribute>
out of the <f:converter>
(or <f:validator>
if you're listening to us) into the input component and then use UIComponent#getAttributes()
to obtain it. E.g.<h:inputText ...>
<f:validator validatorId="valueValidator" />
<f:attribute name="theMaxOrderSize" id="maxorder" value="#{_cartItem.item.maxOrderSize}"/>
</h:inputText>
Object theMaxOrderSize = component.getAttributes().get("theMaxOrderSize");
// ...
component
is the UIComponent
argument of the validate()
method, it represents the parent input component)Integer
or whatever object type the #{_cartItem.item.maxOrderSize}
represents.