这是一个仍然使用休息网址的选项。它不是非常优雅,但可能会完成您正在寻找的东西:
<pretty:link mappingId="LanguageTopic">
<f:param name="link" value="#{currentTopic.link}" />
<f:param name="lang" value="eng" />
English
</pretty:link>
漂亮的config.xml:
<url-mapping id="LanguageTopic">
<pattern value="/topic/#{link:linkBean.link}/#{lang:languageBean.lang}/" />
<view-id>/faces/topic.jsf</view-id>
<action>#{linkBean.cleanUrl}</action>
</url-mapping>
<url-mapping id="Topic">
<pattern value="/topic/#{link:linkBean.link}/" />
<view-id>/faces/topic.jsf</view-id>
</url-mapping>
语言豆:
@ManagedBean(name = "languageBean")
@SessionScoped
public class LanguageBean implements Serializable {
private static final long serialVersionUID = 4460586548949990787L;
/**
* Stores the users language preference
*/
private String lang;
public String getLang() { return this.lang; }
public void setLang(String lang) { this.lang = lang; }
}
链接豆:
@ManagedBean(name = "linkBean")
@RequestScoped
public class LinkBean {
/**
* Stores the resource the user is currently accessing
*/
private String link;
public String getLink() { return this.link; }
public void setLink(String link) { this.link = link; }
/**
* Cleans language specific rest urls to non-specific urls
*/
public void cleanUrl() {
final ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
try {
externalContext.redirect("/topic/" + this.link + "/");
} catch (IOException ex) {
//log or whatever you want here
}
}
}