jsf嵌入复合组件后,如何从ViewHandler中禁用元素? [英] How to disable elements from within a ViewHandler after jsf has embedded the composite component?

查看:101
本文介绍了jsf嵌入复合组件后,如何从ViewHandler中禁用元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果满足某些条件,我正在使用ViewHandler阻止任何访问的页面上的所有输入元素.

I'm using a ViewHandler to block all input elements on any accessed page, if certain criteria is met.

这对于主要" xhtml文件中的输入元素非常有用,但是不会阻止复合组件中的输入元素.我认为这与JSF仅在ViewHandler完成工作后才嵌入这些组件有关.

This works great for the input elements in the 'primary' xhtml files, but the input elements within composite components aren't being blocked. I figured it has to do with the fact that JSF embeds these components only after my ViewHandler has finished it's job.

有人知道如何禁用复合材料中的元素吗?

Does anyone have an idea of how I can disable the elements in the composite as well?

推荐答案

A ViewHandler 是该作业的错误工具.它旨在创建,构建和还原视图,并生成用于JSF表单和链接的URL.并不是要在视图中操作组件.

A ViewHandler is the wrong tool for the job. It's intented to create, build and restore views and to generate URLs for usage in JSF forms and links. It's not intented to manipulate components in a view.

对于您的特定功能要求,请 SystemEventListener PostAddToViewEvent 上是可能是最好的西装.我只是做了一个快速测试,它也适用于复合材料的输入.

For your particular functional requirement, a SystemEventListener on PostAddToViewEvent is likely the best suit. I just did a quick test, it works for me on inputs in composites as well.

public class MyPostAddtoViewEventListener implements SystemEventListener {

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

    @Override
    public void processEvent(SystemEvent event) throws AbortProcessingException {
        UIInput input = (UIInput) event.getSource();

        if (true) { // Do your check here.
            input.getAttributes().put("disabled", true);
        }
    }

}

要使其运行,请在faces-config.xml<application>内部进行以下注册:

To get it to run, register it as follows inside <application> of faces-config.xml:

<system-event-listener>
    <system-event-listener-class>com.example.MyPostAddtoViewEventListener</system-event-listener-class>
    <system-event-class>javax.faces.event.PostAddToViewEvent</system-event-class>
</system-event-listener>

这篇关于jsf嵌入复合组件后,如何从ViewHandler中禁用元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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