Cannot get custom component attribute from backing bean

核能气质少年 提交于 2019-12-12 06:14:48

问题


I have the following custom PrimeFaces Panel

In the page

<x:myPanel panelName="TEST123" />

And the class

    @FacesComponent(namespace="test",tagName="myPanel", createTag=true)
    public class MyPanel extends Panel {

    public MyPanel() {
           panelName = (String)getAttributes().get("panelName");
    }
}

Why when getting the attribute from the class itself does not work

getAttributes().get("panelName");  >> it returns null

I even tried to use the following as well, it also returns null at the class:

<f:attribute name="panelName" value="TEST123"/>

Thanks in advance


回答1:


Basically, behind the scenes, JSF creates the component and sets attributes as below:

MyPanel myPanel = new MyPanel();
myPanel.getAttributes().put("panelName", "TEST123");

It should speak for itself that it's not possible to set a component attribute before it's constructed. However, you're attempting to access it in the constructor!

You should access it in one of the standard UIComponent methods where you actually need it. E.g. encodeBegin() or so.



来源:https://stackoverflow.com/questions/30404268/cannot-get-custom-component-attribute-from-backing-bean

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