以编程方式将ActionListener添加到PrimeFaces MenuItem

时间:2014-07-08 13:14:33

标签: jsf primefaces actionlistener menuitem

我试图以编程方式为menuItem定义一个动作侦听器,然后由菜单使用。在互联网上搜索解决方案,找到了一些例子,但有一些方法没有在PF 4.0中实现(我假设),我该怎么做?这就是我到目前为止所拥有的......

@ManagedBean
@RequestScoped
public class MenuTest implements Serializable{

private MenuModel model;

public MenuTest() {
    model = new DefaultMenuModel();

    MenuItem item;

    item = new MenuItem();
    item.setValue("Menuitem 1"); //Error Here -> Can't find method - 
                                 //Only setLabel or setName available
    item.addActionListener(new MenuActionListener()); // Incompatible types
                 /MenuActionListener cant be converted to Action Listener -> Why?

    model.addMenuItem(item); // Can't find method
    model.addElement(item); // Incompatible types - .
              //Menu Item cannot be converted to Menu Element
}

public MenuModel getModel() {
    return model;
}

}

我的动作侦听器类

public class MenuActionListener implements ActionListener {

    public MenuActionListener() {
    }

    @Override
    public void processAction(ActionEvent event) throws AbortProcessingException{
        System.out.println("Test Action Listener called..");
        System.out.println("Source of the Event is ");
    }

}

0 个答案:

没有答案