Search code examples
validationjsffaceletsicefaces

passing validator to a custom component, fails


I have a simple inputText with a validator:

<ice:inputText
            id="test"
            value="#{applicationBean.selectedApplication['name']}"
            validator="defaultFieldValidator"
            required="true"></ice:inputText>
        <ice:message
            styleClass="graValidationMessage graNotRequired"
            for="test" />

You may have noticed that I specified a validator: defaultFieldValidator and all works fine.

I now make a component to act like a wrapper for the inputText named: inputTextValidated:

<ice:inputText
        id="#{id}#{required}"
        value="#{bean[field]}"
        rendered="#{rendered}"
        styleClass="#{styleClass} #{not required ? 'graNotRequired':''}"
        style="width: #{width};"
        partialSubmit="#{partialSubmit}"
        disabled="#{disabled}"
        required="#{required}"
        validator="#{validatorClass}">
    </ice:inputText>

If I try now to call this component (with the same validator for beginning passed now through a parameter):

<gra:inputTextValidated
                    id="inputText"
                    bean="#{applicationBean.selectedApplication}"
                    field="#{fieldValue}"
                    validatorClass="defaultFieldValidator"
                    renderLabel="false"
                    required="true"
                    disabled="false"
                    width="90%"
                    height="#{secondTabComponentsHeight}">
                </gra:inputTextValidated>

if fails with the following error:

 Identity 'validatorClass' does not reference a MethodExpression instance, returned type: java.lang.String

So the problem is when sending the validator name to my custom component.

Do you see a work-around?

Thanks.


Solution

  • I've ended up using

    <f:validatorId validatorId="#{validatorClass}"/>
    

    inside my inputText component