JSF 2: Change rendered atribute of a component on phase listener

给你一囗甜甜゛ 提交于 2019-12-11 06:24:41

问题


Hy guys,

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

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.

Am I clear?


回答1:


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

}

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>


来源:https://stackoverflow.com/questions/7614508/jsf-2-change-rendered-atribute-of-a-component-on-phase-listener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!