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

标签 java jsf jsf-2 facelets javabeans

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

<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,叫做 Selector:

@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" 更改了上下文。

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

干杯

最佳答案

使用f:setPropertyActionListener .您不需要覆盖 f:ajax 的默认值的 execute 属性(即 @this,唯一的按钮)。

例如

<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 而不是 under_score。我建议将 profile_page 修改为 profilePage。这是 Java,不是 PHP。

关于java - JSF - 使用 ajax 调用更改 panelGroup - Beans、EL 和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4280793/

相关文章:

java - 文件不会删除

c# - C# 中的 TestNG 类似框架

css - 对齐位于另一个 PanelGrid 中的 PanelGrid

java - JSF 2.0 : How to submit a form securely on a HTTP page

Java TreeMap 不够好

java - 使用 log4j2 配置文件设置记录器时

jsf - 如何创建自定义 Facelets 标签?

javascript - 如何获取 h :selectOneMenu 的选定索引

java - DecimalFormat 被服务器设置覆盖

validation - 验证非必填字段