Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
972 views
in Technique[技术] by (71.8m points)

jsf - How do I pass a parameter value to a Conversion class in java?

I am trying to pass a value to a conversion class in JSF/SEAM

public class ValueConverter implements Converter {

public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
    if (StringUtils.isNotBlank(value)) {
    // logic etc here.

My xhtml is:

<f:converter converterId="ValueConverter">
<f:attribute name="theMaxOrderSize" id="maxorder" value="#{_cartItem.item.maxOrderSize}"/>
</f:converter>

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..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Bhesh is entirely right. You should be doing the validating job inside a Validator.

As to the concrete problem, move the <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>

with

Object theMaxOrderSize = component.getAttributes().get("theMaxOrderSize");
// ...

(where component is the UIComponent argument of the validate() method, it represents the parent input component)

You can cast it to Integer or whatever object type the #{_cartItem.item.maxOrderSize} represents.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...