JSF - 使用ajax调用更改panelGroup - Beans,EL和?

时间:2010-11-25 20:55:40

标签: java jsf jsf-2 facelets javabeans

我必须对某些panelGroup UI进行某种切换。 关于视图部分,我做了这个:

<h:panelGroup layout="block" id="profile_content">
    <h:panelGroup layout="block" styleClass="content_title">
        Profilo Utente
    </h:panelGroup>

    <h:panelGroup rendered="#{selector.profile_page=='main'}">
        <ui:include src="/profile/profile_main.xhtml" />
    </h:panelGroup>

    <h:panelGroup rendered="#{selector.profile_page=='edit'}">
        <ui:include src="/profile/profile_edit.xhtml" />
    </h:panelGroup>

    <h:panelGroup rendered="#{selector.profile_page=='insert'}">
        <ui:include src="/profile/profile_articles.xhtml" />
    </h:panelGroup>
</h:panelGroup>

现在,要更改此值,我编写了一个名为Selector的独占JavaBean:

@ManagedBean(name="selector")
@RequestScoped
public class Selector {
    @ManagedProperty(value="#{param.profile_page}")
    private String profile_page;

    public String getProfile_page() {
        if(profile_page==null || profile_page.trim().isEmpty()) {
            this.profile_page="main";
        }
        return profile_page;
    }
    public void setProfile_page(String profile_page) { this.profile_page=profile_page; }
}

所以,现在成功解决了我的问题:当我使用一些h:commandButton更改“上下文”时,我想使用异步调用服务器。这是我的按钮面板:

<h:commandButton value="EDIT">
    <f:ajax event="action" execute="???" render=":profile_content"/>
</h:commandButton>

<h:commandButton value="PM">
    <f:ajax event="action" execute="???" render=":profile_content"/>
</h:commandButton>

<h:commandButton value="ARTICLES">
    <f:ajax event="action" execute="???" render=":profile_content"/>
</h:commandButton>

我不知道要放在execute上的内容,以便我编辑Beans值并使用render=":profile_content"

更改上下文

希望这个问题是可以理解的。原谅我的语言:)

干杯

1 个答案:

答案 0 :(得分:2)

使用f:setPropertyActionListener。您无需覆盖默认的f:ajaxexecute属性(@this,唯一的按钮)。

E.g。

<h:commandButton value="EDIT">
    <f:setPropertyActionListener target="#{selector.profile_page}" value="edit" />
    <f:ajax event="action" render=":profile_content"/>
</h:commandButton>

请注意Java Coding Conventions推荐使用CamelCase over_score。我建议将profile_page修改为profilePage。这是Java,而不是PHP。