Note that there are some explanatory texts on larger screens.

plurals
  1. POCross field validation in jsf h:datatable using p:calendar
    primarykey
    data
    text
    <p>I noticed this question was asked, but it has not been answered correctly.</p> <p>I have a datatable that has two columns <strong>start date</strong> and <strong>end date</strong>. Both contain primefaces p:calendar controls in them. I need to ensure that for each row that the date in column1 is not after the date in column2. I would like to tie this into the JSF validation framework, but I'm having trouble.</p> <p>i've tried marking the datatable rowStatePreserved="true" , this allows me to get the values, but something is still wrong as when it fails, all the values in the first row overwrite all the other values. What am I doing wrong, or should I be using a completely different strategy?</p> <p>xhtml code </p> <pre><code> &lt;h:form&gt; &lt;f:event type="postValidate" listener="#{bean.doCrossFieldValidation}"/&gt; &lt;p:dataTable id="eventDaysTable" value="#{course.courseSchedules}" var="_eventDay" styleClass="compactDataTable" &gt; &lt;p:column id="eventDayStartColumn"&gt; &lt;f:facet name="header"&gt; Start &lt;/f:facet&gt; &lt;p:calendar id="startDate" required="true" value="#{_eventDay.startTime}" pattern="MM/dd/yyyy hh:mm a"/&gt; &lt;/p:column&gt; &lt;p:column id="eventDayEndColumn"&gt; &lt;f:facet name="header"&gt; End &lt;/f:facet&gt; &lt;p:calendar id="endDate" required="true" value="#{_eventDay.endTime}" pattern="MM/dd/yyyy hh:mm a"/&gt; &lt;/p:column&gt; &lt;/p:dataTable&gt; &lt;/h:form&gt; </code></pre> <p>validationCode</p> <pre><code> public void doCrossFieldValidation(ComponentSystemEvent cse) { UIData eventsDaysStable = (UIData) cse.getComponent().findComponent("eventDaysTable"); if (null != eventsDaysStable &amp;&amp; eventsDaysStable.isRendered()) { Iterator&lt;UIComponent&gt; startDateCalendarIterator = eventsDaysStable.findComponent("eventDayStartColumn").getChildren().iterator(); Iterator&lt;UIComponent&gt; endDateCalendarIterator = eventsDaysStable.findComponent("eventDayEndColumn").getChildren().iterator(); while (startDateCalendarIterator.hasNext() &amp;&amp; endDateCalendarIterator.hasNext()) { org.primefaces.component.calendar.Calendar startDateComponent = (org.primefaces.component.calendar.Calendar) startDateCalendarIterator.next(); org.primefaces.component.calendar.Calendar endDateComponent = (org.primefaces.component.calendar.Calendar) endDateCalendarIterator.next(); Date startDate = (Date) startDateComponent.getValue(); Date endDate = (Date) endDateComponent.getValue(); if (null != startDate &amp;&amp; null != endDate &amp;&amp; startDate.after(endDate)) { eventScheduleChronologyOk = false; startDateComponent.setValid(false); endDateComponent.setValid(false); } } if (!eventScheduleChronologyOk) { showErrorMessage(ProductManagementMessage.PRODUCT_SCHEDULE_OUT_OF_ORDER); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload