5 Replies Latest reply on Jul 19, 2007 10:42 AM by steve tynor

    how to set #{invalid} in action

    steve tynor Novice

      I need to do some extra validation in certain actions -- for failed validation, I can set control-specific error messages in the action method via:

      FacesMessages.instance().addToControl("name", new InvalidValue("my error text", MyClass.class, "name", getInstance().getName(), getInstance()));


      but I've not figured out how to set the "invalid" state so that the ${invalid} EL function returns true (without setting invalid, my form displays the error messages, but does not highlight the field input controls in red as a normal HibernateValidation error would.

      Help? (and thanks)


        • 1. Re: how to set #{invalid} in action
          steve tynor Novice

          I've been reading the source (1.2.1-GA), Luke, but am still without enlightenment. In Seam's UIDecorate, I see:

          Contexts.getEventContext().set("invalid", hasMessage(this, context));


          and hasMessage() appears to search down the child components looking for messages -- the input control has one since in my code, I do the following:

          FacesMessages.instance().addToControl("name", new InvalidValue("my error text", MyClass.class, "name", getInstance().getName(), getInstance()));


          You would think that my adding the message to the control would be enough for UIDecorate to find it when it goes searching for messages. It doesn't -- the message is rendered in my facelet, but the label and control are not styled as "error" (which is controlled in the edit.xhtml template via the #{invalid} EL expression).

          So what else do I need to do to cause the UIDecorate to see the message and set the invalid property??


          • 2. Re: how to set #{invalid} in action
            Gavin King Master

            Just look at the booking example, it is working there.

            • 3. Re: how to set #{invalid} in action
              steve tynor Novice

              Thanks Gavin.

              In fact, it's _not_ working in the booking example either. Here's the rendered HTML for failed "date must be in the future" message set by the action class:

              <span id="booking:checkinDateDecorate">
              
               <div class="entry"><label class="label " for="booking:checkinDate">Check In Date:<span id="booking:_id57" class="required">*</span></label>
               <span class="input "><input id="booking:checkinDate" name="booking:checkinDate" type="text" value="07/19/2006" onblur="A4J.AJAX.Submit('_viewRoot','booking',event,{'parameters':{'booking:_id61':'booking:_id61'},'actionUrl':'/seam-booking/book.seam'})" /><script type="text/javascript"><!--
              
              var CAL_DAYS_SHORT = 'Su,Mo,Tu,We,Th,Fr,Sa';
              var CAL_DAYS_MEDIUM = 'Sun,Mon,Tue,Wed,Thu,Fri,Sat';
              var CAL_DAYS_LONG = 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday';
              var CAL_MONTHS_MEDIUM = 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec';
              var CAL_MONTHS_LONG = 'January,February,March,April,May,June,July,August,September,October,November,December';
              var CAL_FIRST_DAY_OF_WEEK = 0;
              var CAL_DATE_FORMAT = 'MM/dd/yyyy';
              //--></script><script type="text/javascript" src="/seam-booking/seam/resource/web/date/calendar.js"><!--
              
              //--></script><span onclick="__selectDate('booking:checkinDate', 'booking:checkinDate');"><img src="img/dtpick.gif" style="margin-left:5px;cursor:pointer" /></span>
               </span><span class="error errors">Check in date must be a future date</span>
               </div></span>



              Note that the message is properly rendered, but the label and controls do not have the errors class added to their CSS style as the edit.xhtml template intends. (should see <label class="label errors" , but instead just see <label class="label " ).


              • 4. Re: how to set #{invalid} in action
                Gavin King Master

                Um, I dunno, it works perfectly for me in CVS....

                • 5. Re: how to set #{invalid} in action
                  steve tynor Novice

                  OK. I'll set this aside until we can upgrade from 1.2.1 to 2.0. Perhaps this will be magically fixed in the upgrade.