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 doubt with h: commandButton (URL no refresh =S) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "doubt with h: commandButton (URL no refresh =S)" Watch "doubt with h: commandButton (URL no refresh =S)" New topic
Author

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

cesar vasde
Greenhorn

Joined: Jan 01, 2011
Posts: 15
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

Joined: Jun 25, 2001
Posts: 16058
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Cesar Loachamin
Ranch Hand

Joined: Dec 25, 2010
Posts: 90

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


When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
Amar Jarubula
Greenhorn

Joined: Jan 18, 2011
Posts: 5
Cesar,
Doesn't using <redirect/> tag create an extra call to server side? Isn't this affecting the performance?
Cesar Loachamin
Ranch Hand

Joined: Dec 25, 2010
Posts: 90

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
 
subject: doubt with h: commandButton (URL no refresh =S)