无法从支持 bean 获取自定义组件属性

Cannot get custom component attribute from backing bean

我有以下自定义 PrimeFaces 面板

在页面中

<x:myPanel panelName="TEST123" />

还有 class

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

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

为什么从 class 本身获取属性时不起作用

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

我什至还尝试使用以下内容,它在 class:

处也 returns null
<f:attribute name="panelName" value="TEST123"/>

提前致谢

基本上,在幕后,JSF 创建组件并设置属性如下:

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

不言而喻,在构建组件属性之前是不可能设置它的。但是,您正试图在构造函数中访问它!

您应该在您 实际 需要它的地方使用标准 UIComponent 方法之一访问它。例如。 encodeBegin()左右。