File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JSF a4j:commandLink isn't working after redirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF a4j:commandLink isn Watch "JSF a4j:commandLink isn New topic

JSF a4j:commandLink isn't working after redirect

Gregory Androsov

Joined: Apr 24, 2013
Posts: 5
Now I write my View presentor using JSF and have some troubles.
I have 2 commandLinks which must change view (it will be realized later). They call redirect-method. Adress bar is chaged from "http://localhost:8080/frontoffice-jsf/main.jsf" "to http://localhost:8080/frontoffice-jsf/main.jsf#1".
After that all two links are inactive (they actions are not called). What can I do? I need to use them more than 1 time.

Please don't watch on String add - it isn't right. Just I tryed to debug it. Problem only in redirection
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16901

Any time you resort to a class in the javax.faces package set that isn't a Model class, there's a good chance you're not doing things right, since JSF is not designed to require much JSF-specific code.

The primary purposes of a JSF action method are to allow action to be taken on the data held in the updated backing bean and connected objects, and to decide where to go next. Originally, the actual "next" was defined abstractly in a faces-config navigation rule that bound a symbolic navigation rule name to an actual target URL. JSF2 allows bypassing the symbolic connection and specifying the target URL directly, which is a mixed blessing.

Navigation target URLs are not the same thing as general URLs. They never include the protocol specifier (http:, https:), hostname, port, or web application context name. They are relative to the root of the application context. Likewise, they cannot include URL parameters "?name=value&name=value", because, as I have said many times before, JSF doesn't expect/want you passing parameters back and forth between Model and View, it expects the Model to retain the parameters. They cannot include page-relative anchor links. The URL extension (for example, ".jsf") is optional. About the only decoration that is allowable is the "#redirect" option that corresponds to the <redirect/> element on the faces-config.xml navigation rule.

I can do something more or less equivalent to what you have illustrated with POJO code, as I will illustrate. Details may vary, since I probably don't have full understanding of what you want, but at least I hope it will serve as a guideline.

First, I'm going to postulate that you have your navigation map as a Session or Application scope Managed Bean named navMap and that the key in the map is the display name and that the value is the View target navigation URL. The map is a custom of Map and presents a "rows" property which presents model name/value row class objects, because although I could probably do this against a generic Map, I'd have to RTFM and I want to keep this simple/easy.

Here goes:

Now the model essentials:

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: JSF a4j:commandLink isn't working after redirect
It's not a secret anymore!