• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Newbie question on RELOAD or REDIRECT?

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Leo. I appreciate your help and time in responding. I'll try your suggestions.
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic