1

I'm using primefaces 2.2.1 and I want set f:validatorLength to one row in datatable with many rows with p:cellEditor.

<c:set var="flag" value="#{item.key eq 'someKey'}" />
<p:column headerText="header">
    <p:cellEditor>
       <f:facet name="output">
        <h:outputText value="#{item.value}" />
            </f:facet>
               <f:facet name="input">
                <p:inputText value="#{item.value}" style="width:100%" >
    <f:validateLength maximum="4" disabled="#{flag}"/>
                </p:inputText>

                </f:facet>
    </p:cellEditor>
</p:column>

And when flag is true for chosen inputText with appropriate key, then validator turn on for all inputTexts. And when flag is false - validator turn on for all inputTexts. But I want set validator to some inputTexts and so on. Any ideas? Thanks.

MaximG
  • 141
  • 2
  • 3
  • 12

1 Answers1

2

This is a known problem. The attributes of <f:validateXxx> tags are evaluated during view build time. So they can't depend on a variable which is only available during view render time.

This is basically the same problem as outlined and answered in detail here: How to set converter properties for each row of a datatable?

In your particular case, apart from homegrowing a validator yourself which programmatically evaluates #{item} inside the validate() method, you could use OmniFaces <o:validator> which enables render-time evaluation of all attributes.

<p:inputText value="#{item.value}">
    <o:validator validatorId="javax.faces.Length" maximum="4" disabled="#{flag}" />
</p:inputText>
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you. I'm create my own validator. It works! And now I have another problem. I want to update (messages element with error) after clicking ('cancel') in cellEditor. How can I do it in PF 2.2.1? In 3.4 we have ajax event "rowEditCancel" and it must work, but what about in 2.2.1? Thank you! – MaximG Nov 23 '12 at 09:11