File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How to reset form for Viewscoped managed bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to reset form for Viewscoped managed bean " Watch "How to reset form for Viewscoped managed bean " New topic
Author

How to reset form for Viewscoped managed bean

Sachin Yewale
Greenhorn

Joined: Feb 02, 2012
Posts: 21
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

Joined: Jun 25, 2001
Posts: 16020
    
  20

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Sachin Yewale
Greenhorn

Joined: Feb 02, 2012
Posts: 21
Hi Tim,
Thanks for reply. My problem is solved now . I called same page directly by using action="mypage" attribute.
Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to reset form for Viewscoped managed bean