• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie question on RELOAD or REDIRECT?

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Leo. I appreciate your help and time in responding. I'll try your suggestions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic