JSF - Изменить PanelGroup с помощью вызовов ajax - Beans, EL и? - PullRequest
3 голосов
/ 25 ноября 2010

Мне нужно сделать что-то вроде переключателя некоторого panelGroup пользовательского интерфейса.Что касается раздела просмотра, я сделал это:

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

Надеюсь, что этот вопрос понятен.Прости меня за язык:)

Ура

1 Ответ

2 голосов
/ 26 ноября 2010

Использование f:setPropertyActionListener. Вам не нужно переопределять атрибут по умолчанию f:ajax execute (который является @this, единственная кнопка).

1011 * Е.Г. *

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

...