Re: Beginner needs help with basic prettyfaces concepts

Splash Forums PrettyFaces Users Beginner needs help with basic prettyfaces concepts Re: Beginner needs help with basic prettyfaces concepts

#20412

There are multiple ways to achieve something like this. One option is to use the Inbound-URL-Rewriting feature of PrettyFaces. Just add a rewrite rule to your pretty-config.xml like this:

<rewrite match="/" substitute="/lang/fr/" redirect="301"/>

If you want to have more control what language to set for the redirect, you could also use a regular URL mapping like this one (pseudo code):

@URLMapping(id = "start", pattern = "/", viewId = "/something.jsf")
public class StartPage {

@Inject / @Autowired / something similar
private AccueilViewBean accueilView;

@URLAction
public String action() {

// get the language by looking up the default language
// for the user or something like that
String lang = .....;

// set value to the correct property
accueilView.setLanguage(lang);

// send redirect to the target page.
// the language to use for the link will be extracted
// from the 'accueilView' bean.
return "pretty:rootAction";

}

}

Unfortunately you will need a “/something.xhtml” file, although it will not be rendered as the URL action will execute a redirect. But this file can be empty. It is required to be able to enter the JSF lifecycle for this request.

Here are a few links that may be interesting for you:

http://ocpsoft.com/docs/prettyfaces/snapshot/en-US/html_single/#inbound_rewriting

http://ocpsoft.com/docs/prettyfaces/snapshot/en-US/html_single/#navigation.actions