Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to reset form for Viewscoped managed bean

 
Sachin Yewale
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , friends i want to know how can i reset form values in jsf 2.0 if bean is in viewscoped. i read in one of post that you can remove by using code :


But it is not working . form values remains same.
Please help me.
Thanks in advanced.

 
Tim Holloway
Saloon Keeper
Posts: 18303
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like so many other cases, this is something that shouldn't be done using JSF-specific code. In fact, my #1 rule for JSF is that the more JSF-specific the code is, the more likely it is that it's being done wrong.

Instead of mucking around with JSF's internal bean management, write an init() method that clears all of the bean's property values in a POJO way. I invoke this method in the constructor so that the same initial state (values) is created when the bean is first constructed, so both the constructor and the reset() method would invoke init().

If reset() is an action method invoked from the corresponding View, then the normal JSF lifecycle view-update processing will reset the values on the displayed form (to the values that init() set).

Note that you should not use a JSF "reset" button control to invoke the reset() method, since that control generates an HTML RESET control, which restores the values to their initial page-load settings on the client side without invoking any server-side code. Including the reset() method.
 
Sachin Yewale
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,
Thanks for reply. My problem is solved now . I called same page directly by using action="mypage" attribute.
Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic