Executing the ActionListener of a (Primefaces) menu item leads to an IllegalStateException

前端 未结 2 1742
有刺的猬
有刺的猬 2020-12-19 07:50

In JSF backed bean I got an IllegalStateException when the programmatically added action listener of a programmatically added Primefaces menu item is called. I

2条回答
  •  北海茫月
    2020-12-19 08:27

    EL (read: reflection) cannot access/construct anonymous classes. Refactor them into fullworthy classes.

    So, replace

        item.addActionListener(new ActionListener() {
            @Override
            public void processAction(ActionEvent event)
                    throws AbortProcessingException {
                System.out.println(event.toString());
            }
        });
    

    by

        item.addActionListener(new FooActionListener());
    

    and

    public class FooActionListener implements ActionListener {
    
        @Override
        public void processAction(ActionEvent event)
                throws AbortProcessingException {
            System.out.println(event.toString());
        }
    
    }
    

    See also:

    • How to invoke a JSF action on an anonymous class?

提交回复
热议问题