Announcement Announcement Module
No announcement yet.
spring faces: User interface inconsistent with model? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring faces: User interface inconsistent with model?

    I have noticed a strange behavior (maybe bug?) that happens when displaying a faces view state after executing a transition with no target (event handler). The result is that the user interface displays stale data and is inconsistent with the model.


    I have a view state which presents a form. No ajax is used. The view state has a transition with no target (event handler) that is executed when the form is submitted.

    1) Fill out every field in the form. In one of the fields (say field A) enter a value that will cause a conversion error. For example enter a string where a number or date is expected.
    2) Submit the form. The screen loads again showing all the fields as entered. The conversion error is reported for field A.
    3) Now fix field A where the conversion error happened but also change a valid field (say field B) to a different valid value.
    4) The form is submitted successfully, the transition executes, actions are called, etc, etc. The model is updated with the correct values for fields A and B. Because the transition has no target the same view is displayed again. THE PROBLEM IS: field B shows the previous value, which is the value that was entered during the first submission of the form!


    This scenario is quite common in search by criteria screens where the results are displayed on the same screen. The event handler executes the search and the same view state is displayed with the search results.


    I have made a few modifications to the swf-booking-faces sample code to reproduce this issue. Just replace the files booking-flow.xml and enterBookingDetails.xhtml with the ones I have attached below. Try to book a hotel. In the enter booking details screen, enter a non valid string for "check-in date". Submit the form. A validation error is displayed. Then enter a valid value for the "check-in date" but change another field, say "Credit card name" to another valid value. Submit the form. You will notice that "Credit card name" displays its previous value.


    From a little debugging I did, I think the sequence of events that causes this behavior is the following:

    form is filled (includes a field value that will cause a conversion error) and submitted
    component tree is updated with submitted values
    processing stops because of conversion error
    component tree state is saved (the saved state includes the field values that were submitted and converted successfully - set as component "local values")
    view is displayed
    (all the above is within a single request - response)

    form is filled and submitted with valid but different values
    component tree state is restored (includes previous local values of valid fields)
    component tree is updated with new submitted values
    processing completes successfully
    a redirect command is returned to the client (because of the POST-REDIRECT-GET idiom)

    the client sends a GET request for the same view
    component tree state is restored as it was last saved (previous local values!!)
    the view is rendered with incorrect values

    I noticed this behavior some time ago in version 2.0.3 but it hasn't changed in 2.0.4 either. I see 2.0.5 is also out now. If this turns out to be a bug, I hope I didn't report it too late to be addressed before 3.0.0.

    Thanks for reading!
    Last edited by nkaza; Nov 17th, 2008, 10:15 AM.

  • #2
    Yes, I think you're correct that this could actually be considered a bug. The way targetless transitions are handled in the non-Ajax case changed around 2.0.3 (now we do a redirect if it's not an Ajax request, where before we did not for targetless transitions), and we've not properly compensated for this in Spring Faces.

    Can you open a Jira for this, referencing this thread? We'll have to address this in a 2.0.6 release.


    • #3
      It might be good to have a general discussion on the subject of redirecting after processing POST events. We definitely do not redirect when there are view errors on postback--we render the current view in the same postback request and if the user attempts to refresh, they get a warning that they are posting invalid data. We do redirect by default, however, after each successful POST, including those POSTs that don't change the current flow view-state ... which is the scenario where this problem can show up [as component state is not being saved out before the redirect]. Thoughts on the ideal redirect behavior in general? You can see the current logic in Without a redirect you will get a browser warning on refresh even after processing the POST successfully.

      Last edited by Keith Donald; Nov 17th, 2008, 05:03 PM.


      • #4
        Opened the Jira issue: