This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt with h: commandButton (URL no refresh =S)

 
cesar vasde
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to this example here, in a commandButton can put this:

<h:commandButton action="/shopping/page2" value="Submit" />

I'm working that way in my application. The problem I have is that the url does not refresh in the browser

For example: In page1.xhtml I have commandButton with action="/pages/page1.xhtml"

This button should take me to a page named page1.xhtml. But it does not, the view is updated but the URL of the browser still has the same url above.

Ie in the browser says /page/page1.xhtml but in reality I'm on page 2

This brings me to future problems, as sometimes the browser gets stuck and does not know which page to send

Help please

 
Tim Holloway
Saloon Keeper
Pie
Posts: 17624
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF URLs are not used the same way as most other webapp frameworks use them. They are more like session handles than absolute resource locators, which is why a postback operation doesn't return with the new page's direct-access URL in the browser toolbar.

The mechanism works just fine as long as you realize that a direct URL and a 'session handle' URL are not the same thing and you don't set up brute-force hyperlinks and expect that they'll contain the JSF session information (which is NOT the same thing as HttpSession!). A Session handle only works when submitted via POST, not GET, since the postback includes the JSF session information as part of the POST data stream.

You can forcibly update the displayed URL in the toolbar using the <redirect/> navigation option, but there is extra overhead when you do that.
 
Cesar Loachamin
Ranch Hand
Posts: 90
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cesar

Tim's explanation is excellent, if you need to refresh the address you must you redirection, it's slow, however the redirection gives the browser a chance to update it's adress field.
Here I give you a examples of how to use redirection
In the <h:commandButton>

And if you're using navigation rules you need to add the <redirect/> in the section <navigation-case> of your faces-config.xml file, for example

Regards
Cesar
 
Amar Jarubula
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cesar,
Doesn't using <redirect/> tag create an extra call to server side? Isn't this affecting the performance?
 
Cesar Loachamin
Ranch Hand
Posts: 90
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amar

You're right the redirect option causes the client browser to make a new HTTP request for the specified view as opposed to just rendering the response without requiring a separate HTTP request. Regarding the performance, using a redirect will terminate the current request and cause a new request - response cycle to occur. If the page has a very large set of components, this could have a noticeable performance impact. Redirects can also necessitate an extra round trip to reinstantiate any request-scoped objects that have disappeared by the next request.

Regards
Cesar
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic