How to pass parameter value to 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:

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

How to pass parameter value to Conversion class in java? Am I starting wrong? I am using JSF 1.2, I think.

+3
source share
2 answers

Bash is absolutely right. You must do the verification work inside Validator.

For a specific problem, move <f:attribute>from <f:converter>(or <f:validator>, if you are listening to us) to the input component, and then use UIComponent#getAttributes()to get it. For instance.

<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 componentis the argument of the UIComponentmethod validate(), it represents the parent component of the input)

Integer , #{_cartItem.item.maxOrderSize}.

+6

Validator. String Object Object to String. .

Conversion java?

, . -

JSF?

FacesContext -

context.getExternalContext().getRequestParameterMap();

, . !

, StateHolder -

public class ValueConverter implements Converter, StateHolder {
+3

All Articles