Results 1 to 4 of 4

Thread: Overriding backing bean values and clearing forms

  1. #1
    Join Date
    Jun 2009
    Posts
    4

    Question Overriding backing bean values and clearing forms

    Hello,

    I am using JSF views (Facelets, MyFaces and Tomahawk) rendered under SWF 2.

    I have a 'clear' button on a page, and I want that button to clear the form fields (without validating the input).
    This was easily doable in pure JSF, by setting the immediate attribute to true (on the commandButton) and calling JSF's renderResponse().

    I am now trying to do the same thing under WebFlow (2.0.6), but can't get it to work.

    Here are some snippets from my code:
    .xhtml:
    Code:
    <t:commandButton styleClass="btnDesign" action="effacerGlobal" value="Effacer"/>
    flow.xml:
    Code:
    <view-state id="INDIVIDU" view="rechercheClient.xhtml">
    <var name="criteres" class="gouv.ctq.sim.dto.client.CriteresClient115" />
         <transition on="effacerGlobal" to="INDIVIDU">
    			<evaluate expression="rechercheClient.effacerBloc(criteres)" />
    			<render fragments="whateverform" />
    		</transition>
    </view-state>
    and the "effacerBloc(...)" method simply clears fields from the 'criteres' object.

    It seems to work, since the view is effectively rendered with empty fields when I set the 'immediate' attribute to false on the commandLink (but then the fields are converted/validated, and I don't want that...)

    I am looking for a way to render an empty form again without validating any of the fields. I tried adding a fragment to the view, and using a <render> tag in the transition, but it didn't work.

    Thanks for your help!

  2. #2
    Join Date
    Nov 2008
    Posts
    742

    Default

    What you're doing should be working. I've got the same kind of thing: a form with some validators (required and such) and a reset button. The reset commandButton has immediate="true", and performs a transition back to the same state, calling the reset method on my form.

    You didn't specify what happens when you do the same thing. Are the fields not being cleared, or is the validation still performing? Also, does the same thing happen if you switch to an h:commandButton?

  3. #3
    Join Date
    Jun 2009
    Posts
    4

    Default

    Thanks.

    As you pointed, I think my first post lacks some info.
    First, the effacerBloc(...) method returns a void type and does not throw any exception, so the transition flow should not be affected.
    When I set the immediate attribute to true, the validations are not carried out and the effacerBloc method is called, but the rendered view still shows the original values.

    I debugged a bit and traced the HTTP request/responses (to be sure that the data wasn't coming from any kind of browser cache).
    Here's what I see:
    (if immediate is set to false)
    1) Value binding, conversion and validation occurs (and transition is not executed if it fails)
    2) Method effacerBloc(...) is called and clears fields
    3) Response is generated, and the cleared fields are empty

    (If immediate is set to true)
    1) Method effacerBloc(...) is called, and fields are cleared
    2) Through debugging and trace statements, I confirmed that no data binding occurs after the effacerBloc(...) has been called
    3) The HTTP response received indeed contains the values submitted by the client <- This is the part I don't get...

    I tried using h:commandButton instead of t:commandButton, and didn't notice any change...

    Is there a way to force the response to be generated using the dataModel (and to discard the values submitted by the client) while setting immediate=true?

  4. #4
    Join Date
    Nov 2008
    Posts
    742

    Default

    I may have found the problem. Check out this known issue in SWF 2.0.6. Upgrading to SWF 2.0.7 should fix your issue, but a workaround is also included in the bug description.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •