How to disable elements from within a ViewHandler after jsf has embedded the composite component?

后端 未结 1 1849
南笙
南笙 2021-01-25 09:15

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

This works great for the input elements in the \'primary\' xhtml f

相关标签:
1条回答
  • 2021-01-25 10:04

    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.

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

    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>
    
    0 讨论(0)
提交回复
热议问题