无法从支持Bean获取自定义组件属性 [英] Cannot get custom component attribute from backing bean

查看:101
本文介绍了无法从支持Bean获取自定义组件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下自定义PrimeFaces面板

I have the following custom PrimeFaces Panel

页面中

<x:myPanel panelName="TEST123" />

和班级

    @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

我什至也尝试使用以下内容,该类也返回null:

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

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

预先感谢

推荐答案

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

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!

您应该在标准 UIComponent 您实际需要的方法。例如。 encodeBegin()左右。

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

这篇关于无法从支持Bean获取自定义组件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆