7 Replies Latest reply on Oct 16, 2010 8:08 AM by Milan Pevec

    Seam field validation with no model update

    Philip Murphy Newbie

      Hi,


      The behaviour I would like to see is as follows:


      1) User edits a field (pre-populated with data from entity).

      2) Field validation occurs when user tabs out of field, however the model should not be updated.

      3) If user changes data to some other valid entry when leaving the field it should hold this value in the field but not update the model.

      4) User presses command button to commit the changes.


      The problem I am facing is that after step 3 (on leaving the field) the field reverts back to the original value and the user's change it lost.


      Here is a snippet of the xhtml I am using:-


      <a4j:form>
      
      <s:decorate id="startTimeDecorate" template="edit.xhtml">
        <ui:define name="label">Start Time</ui:define>
        <h:inputText id="startTime" required="true" value="#{_event.startTime}">
          <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{myAction.timeZone}" />
          <a4j:support event="onblur" reRender="startTimeDecorate"  bypassUpdates="true" ajaxSingle="true" />
        </h:inputText>
      </s:decorate>
      
      <a4j:commandButton id="updateEvent" value="Update Event" reRender="startTimeHeader" />
      
      </a4j:form>
      
      



      If someone would have a solution to this I would be very grateful.


      Thanks,


      Philip

        • 1. Re: Seam field validation with no model update
          Binesh Gummadi Novice

          On your a4j:commandButton


          bypassUpdates="true" 



          • 2. Re: Seam field validation with no model update
            Binesh Gummadi Novice

            My bad. I should have read the whole post :(


            I have a similar use case and I used hibernate validator to validate my start time. I do not have jsf converter. It works for me.

            • 3. Re: Seam field validation with no model update
              Philip Murphy Newbie

              Hi Binesh,


              Thanks for the reply. So you think that the f:convertDateTime is interfering with the behaviour of the field? Seams a bit weird that a built in converter is causing the field to revert back to it's original value. Could this be considered a bug?


              Thanks,


              Philip

              • 4. Re: Seam field validation with no model update
                Philip Murphy Newbie

                BTW, I can't change the validation rule on the entity as the entity will be used by different systems that require different date patterns etc. i.e. I have to keep the yyyy-MM-dd HH:mm:ss date pattern at the JSF level. Therefore I can't use your suggestion. If anyone else has any other solutions please post.

                • 5. Re: Seam field validation with no model update
                  Binesh Gummadi Novice

                  I modified my code and tested it with f:convertDateTime and it works as expected. The only change is, I do not have is the timezone. All 4 steps works for me. So, this is not a bug. How is your event object populated? what is the scope of the event ?

                  • 6. Re: Seam field validation with no model update
                    Philip Murphy Newbie

                    Hi Binesh,


                    Thanks for taking the time to test if this is working. Note that the original JSF snippet that I sent is wrapped within a a4j:repeat. Details follow of my set up.


                    Cheers,


                    Philip


                    Entity Class


                    @Entity
                    @Table(name = "event")
                    public class Event implements java.io.Serializable {
                    .
                    .
                    .
                    }
                    
                    



                    Backing Bean


                    @Stateful
                    @Name("myAction")
                    @Scope(ScopeType.SESSION)
                    public class MyActionImpl implements MyAction {
                    
                      @PersistenceContext(type = PersistenceContextType.EXTENDED)
                      private EntityManager entityManager;
                    
                    
                      @DataModel("myAction_events")
                      private List<Event> events;
                    
                      public void searchEvents() {
                        entityManager.createQuery("SELECT e FROM Event e");
                        events = (List<Event>) q.getResultList();
                      }
                    }
                    


                    JSF


                    <a4j:repeat value="#{myAction_events}" var="_event">
                    
                      <a4j:form>
                    
                        <s:decorate id="startTimeDecorate" template="edit.xhtml">
                          <ui:define name="label">Start Time</ui:define>
                          <h:inputText id="startTime" required="true" value="#{_event.startTime}">
                            <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{myAction.timeZone}" />
                            <a4j:support event="onblur" reRender="startTimeDecorate"  bypassUpdates="true" ajaxSingle="true" />
                          </h:inputText>
                        </s:decorate>
                    
                        <a4j:commandButton id="updateEvent" value="Update Event" reRender="startTimeHeader" />
                    
                      </a4j:form>
                    
                    </a4j:repeat>
                    
                    

                    • 7. Re: Seam field validation with no model update
                      Milan Pevec Newbie

                      Hi Philip,


                      did you find a solution of above problem? I have the same problem and i think that a:repeat has something to do with it, look at:


                      My Link


                      The solution is using bypassUpdates to false,but this canbe  very  dangerous...


                      Thanks


                      Milan