Validation in primefaces datatable calendar cell

UI Components for JSF
Post Reply
amah117
Posts: 2
Joined: 30 Mar 2017, 12:01

18 Jan 2018, 18:03

I have couple of Calendar columns in a datatable

Code: Select all

<p:column headerText="Time From" >
        <p:cellEditor>
            <f:facet name="output">
                <p:calendar pattern="dd/MM/yyyy HH:mm:ss.SSS" value="#{aa.timeFrom}"/>
            </f:facet>
            <f:facet name="input">
                <p:calendar pattern="dd/MM/yyyy HH:mm:ss.SSS" value="#{aa.timeFrom}"/>
            </f:facet>
        </p:cellEditor>
    </p:column>

    <p:column headerText="Time To">
        <p:cellEditor>
           <f:facet name="output">
               <p:calendar pattern="dd/MM/yyyy HH:mm:ss.SSS" value="#{aa.timeTo}"/>
           </f:facet>
           <f:facet name="input">
               <p:calendar pattern="dd/MM/yyyy HH:mm:ss.SSS" value="#{aa.timeTo}"/>
           </f:facet>
       </p:cellEditor>
    </p:column>
And also a "submit" button:

Code: Select all

<p:commandButton value="Submit" action="#{aa.submit}" />
Calendar picker is displayed when mouse button is clicked in a cell. The user can either pick a date/time or enter a value in the cell. If an invalid value such as "123456" is entered and then mouse is clicked in another cell, the cell border of the invalid cell is displayed as red and the following error message is displayed:

"'123456' could not be understood as a date and time. Example: 15/01/2018 11:54:02.247"

The submit action is called when the user clicks on "submit" button. The problem is that in the submit action, the invalid values returned are null and not the values entered by the user. The valid values are correctly set. How can I get the invalid values entered by the user in the submit action? In the above example, I would like to get "123456" instead of null.

If invalid values cannot be returned, then is it possible to find which cells have invalid values in the submit action? I want to distinguish between values not entered and invalid values entered (Both of the date/times are optional).

Post Reply
  • Information