0

我正在使用漂亮的面孔来处理 URL 路径。

我想要做的是在点击链接后设置语言属性(选择语言)。像这样的东西:

<h:link outcome="#{bean.currentPath}" value="English"> <!-- path goes to self -->
    <f:param name="link" value="#{currentTopic.link}" />
    <f:param name="lang" value="eng" />
</h:link>

prettyconfig 检索链接并跟随它,但我怎样才能将参数发送到语言 bean?

<url-mapping id="">
    <pattern value="/topic/#{link:bean.link}" />
    <view-id>/faces/topic.jsf</view-id>
</url-mapping>

bean 是无状态的 (@RequestScoped),而语言 bean 是有状态的 (@SessionScoped)。两者都是@ManagedBeans。

4

1 回答 1

1

这是一个仍然使用休息网址的选项。它不是非常优雅,但可能会完成您正在寻找的东西:

<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
        }    
    }
}
于 2011-05-12T16:59:52.117 回答