• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

How to reset form for Viewscoped managed bean

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Saloon Keeper
Posts: 25646
183
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
We're all out of roofs. But we still have tiny ads:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic