JSF 2:更改在阶段侦听器上呈现的组件属性 [英] JSF 2: Change rendered atribute of a component on phase listener

查看:130
本文介绍了JSF 2:更改在阶段侦听器上呈现的组件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在JSF 2中,如何使用PhaseListener更改h:InputText组件的渲染属性.

In JSF 2 How can I change the rendered atribute of a h:InputText component using a PhaseListener.

在呈现jsf页面之前,我必须验证h:inputtexts的所有ID,然后再更改要呈现的属性.

Before the jsf page be rendered I have to verify all id of the h:inputtexts, and after that I will change the atribute to be rendered or not.

我明白了吗?

推荐答案

在GET请求中,在渲染响应的前阶段尚未创建视图根,而在后阶段则已为时已晚,因为响应已经存在呈现并发送给客户端.但是,视图根可在预渲染视图"系统事件期间进行修改.

On GET requests, the view root is not created yet during the before phase of the render response and during the after phase it's too late because the response is already been rendered and sent to the client. The view root is however available for modification during the "pre render view" system event.

public class PreRenderViewListener implements SystemEventListener {

    @Override
    public void processEvent(SystemEvent event) throws AbortProcessingException {
        UIViewRoot root = (UIViewRoot) event.getSource();
        // ...
    }

    @Override
    public boolean isListenerForSource(Object source) {
        return true;
    }

}

要使其运行,请在faces-config.xml中进行如下注册:

To get it to run, register it as follows in faces-config.xml:

<application>
    <system-event-listener>
        <system-event-listener-class>com.example.PreRenderViewListener</system-event-listener-class>
        <system-event-class>javax.faces.event.PreRenderViewEvent</system-event-class>
    </system-event-listener>
</application>

这篇关于JSF 2:更改在阶段侦听器上呈现的组件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆