Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF Page should not refresh on click of JSF button

 
Md Ibrahim
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi all,

we all know that any action performed on JSF usually refreshes whole page.
In the below code

<h:commandButton value="OK" action="#{BackingBean.callmethod}"/>

On click of this JSF page command button, whole page gets refreshed, since the button is by default a submit type button.

But if we use <h:commandButton value="OK" type ="reset" action="#{BackingBean.callmethod}"/>
then page wont get refreshed but the problem is Backing bean values will not be submitted.

And i know we can do this by AJAX and many more advance technologies, but my requirement is with out AJAX

Please do reply how to submit a JSF page with out page refresh and also populating corresponding backing bean values.


BY,
Ibrahim


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets. For more information, please read this.

This post has been moved to a more appropriate forum.
 
Bart Kummel
author
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ibrahim,

Using a "reset" type button is certainly not the way to prevent the page from being reloaded. The fact that the whole page gets reloaded is not a limitation of JSF but of HTML and HTTP. It is due to the fact that HTML forms were designed to be submitted as a whole after which a new page was to be displayed.

In recent years, more and more web applications found solutions to not reload the page when data is submitted. The techniques used for this are now known as AJAX. There is no other way to submit data to a server without reloading the page. (Unless you are using non-HTML technologies like Flash, Silverlight or Java applets...)

So if you want to submit data without reloading the page, you should rethink your "no AJAX" requirement. If the reason for this is that you don't want to write JavaScript, I have good news for you: you don't have to. By using JSF components that are "AJAX enabled", you get non-reloading pages without much effort and without writing JavaScript. A good example of a set of JSF components that do the hard AJAX work for you is the Apache MyFaces Trinidad project.

My book, Apache MyFaces 1.2 Web Application Development, has a lot of information about building JSF pages with AJAX functionality, without having to do the hard work yourself. That is one of the largest benefits of using JSF: it creates an abstraction layer, so that you don't have to bother about HTML, JavaScript or CSS.

Best regards,
Bart Kummel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic