aspose file tools*
The moose likes JSF and the fly likes Making URLs relevant with JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Making URLs relevant with JSF" Watch "Making URLs relevant with JSF" New topic
Author

Making URLs relevant with JSF

Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
One issue I've had with JSF is the lack of importance of a URL in the browser. It seems that since everything is a post, it's difficult, if not impossible, to create a web app that considers URLs important. A blog would be a good example. Something like "detail.jsf?id=1234" just isn't something handled well by JSF.

Is this something others have struggled with? I'd be curious to hear any suggestions on how to overcome this in JSF.
Darryl Nortje
Ranch Hand

Joined: Jun 11, 2002
Posts: 140
Howzit Chris,

This post got me. I couldn't believe that it's not possible, and to my horror found out that if it is in fact possible, it most definately not intuitive, or obvious. So I also started searching, and found one of Balus C's topics that seems to cover it. I am still reading through it, but so far, judging by the intro, it seems to have something to do with this. So thought, while I'm going through it, you could too ;-)
Here it is
Zack Marrapese
Greenhorn

Joined: Jul 02, 2008
Posts: 27
You can put any GET data into a backing bean by setting a managed property on it. For example, with the URL detail.jsf?id=1234 and a backing bean, foo with a property called id:



and now you can access that property like any other. Note, however, that because this is a managed property it can't be accessed until after construction...create a @PostConstruct function if you can.

Hope this helps
~Zack
[ July 03, 2008: Message edited by: Zack Marrapese ]
Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
Do you know how to invoke the action when setting a managed property? Say I have a hyperlink to a blog entry, like "detail.jsp?id=123". When that link is clicked, there's no default action or anything, so is there a special component I should use to specify the action I want to execute while passing the id as a GET parameter?
Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
A quick update. I used h:commandLink to invoke an action once the link is clicked, however, using the navigation rules in the faces-config only forwards the process to another page, it has no effect on the URL displayed in the browser. That makes it impossible for the user to know the actual URL they are on, and makes it so they can't bookmark it for future reference. How can I get around this?

index.jsp


detail.jsp


LoginBean.java


faces-config.xml
Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
Anyone?
Ayub ali khan
Ranch Hand

Joined: Oct 20, 2005
Posts: 380
    
    2
Hi Chris,

I think <redirect/> should be useful for your requirement.

Check Navigation

--Ayub


SCEA part I,TOGAF Foundation
Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
While that element looked promising, it ends up breaking the application I posted above. When you click the link from the index.jsp page, it does in fact forward to the detail.jsp page, but the ID value of the bean is 0 instead of the value set in the link. It works as expected without the element in the faces-config.xml file.
Ayub ali khan
Ranch Hand

Joined: Oct 20, 2005
Posts: 380
    
    2
I suggest you have a look at Thisdiscussion so as to decide your approach of implementation.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Making URLs relevant with JSF