2010-11-25 46 views
3

我必须做一些panelGroup用户界面的切换。 关于视图部分,我做了这个:JSF - 通过使用ajax调用改变panelGroup - Bean,EL和?

<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> 

现在,修改这个值,我写了一个专属的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,使我编辑的豆类价值,我用render=":profile_content"

希望这个问题是难以理解的更改上下文。请原谅我对语言:)

干杯

回答

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 under_score。我建议修复profile_pageprofilePage。这是Java,而不是PHP。

+0

感谢您对CamelCase的建议。是的,这是有效的。我觉得奇怪的是,如果我删除,它会向服务器发出正常的请求(页面被重新加载)。否则,如果我添加,则以前的ActionListener将以异步方式工作。奇怪的行为,我需要了解为什么会发生这种情况:) – markzzz 2010-11-25 21:31:52