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 Newbie question on RELOAD or REDIRECT? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Newbie question on RELOAD or REDIRECT?" Watch "Newbie question on RELOAD or REDIRECT?" New topic
Author

Newbie question on RELOAD or REDIRECT?

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

I have a very simple JSP page that contains a form. When the user completes the form I would like to RELOAD the same page with blank fields and a message at the top that states that the previous record was submitted successfully.

In reading some of the posts in the JSF forum I cannot get a clear picture of how to accomplish that task.

I understand that the bean that is being executed when the SUBMIT button is clicked has to return a value from that bean and reference that in my <from-outcome> tag in my faces-config.xml file:

<navigation-rule>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/index.jsp</to-view-id>
</navigation-case>
</navigation-rule>

What happens when I click submit with this scenario I get the following result:

The same page is reloaded but with the same values that I entered. Any suggestions on how I can add my success message and clear all the values or reload the same page as if I clicked on the URL for the first time?

Any help/direction would be greatly appreciated. Thank you.

leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
When the user completes the form I would like to RELOAD the same page with blank fields and a message at the top that states that the previous record was submitted successfully

Ok. Your action method could return null which would cause the same page to redisplay.

Any suggestions on how I can add my success message...


Yes. The h:message tag will display a success message for any JSF element to which you assign an id attribute.
Example:


Or, you could wire a bean property to an <h:outputLabel /> tag.

...and clear all the values or reload the same page as if I clicked on the URL for the first time?

Well, assuming your web application is session scoped, and your text field uses a method binding value, you'll have to set that bean property to an empty string, *after* whatever you do with your record submission logic and before your return value for navigation.

Once you display the message, the only way to get rid of it is to invalidate the session, or wait for it to time out - or come up with a JavaScript hack.


Thanks, leo
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

Thanks, Leo. I appreciate your help and time in responding. I'll try your suggestions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie question on RELOAD or REDIRECT?