【问题标题】:How to add custom attributes for custom components in jsf?如何在jsf中为自定义组件添加自定义属性?
【发布时间】:2017-11-07 09:00:58
【问题描述】:

我在 JSF 的 taglib.xml 中创建自定义组件,如下面的代码

     <tag-name>CustomComponent</tag-name>
   <component>
            <component-type>javax.faces.Input</component-type> 
    </component>
      </tag>

在 xhtml 中渲染组件,如下所示

<h:body bgcolor="white">
<cs:CustomComponent></cs:CustomComponent>       
            </h:body>

我想为这个组件添加自定义属性。如果除了我指定的任何其他参数,并且想要抛出警告。 jsf可以做到吗?

【问题讨论】:

    标签: jsf jsf-2 custom-component


    【解决方案1】:

    看这里

    <tag>
    <tag-name>training</tag-name>
    <attribute>
        <name>style</name>
    </attribute>
    <attribute>
        <name>action</name>
        <method-signature>java.lang.String action()</method-signature>
    </attribute>
    <component>
        <component-type>training</component-type>
        <renderer-type>pl.spiid.app.spiidcharts.beans.training.Training</renderer-type>
    </component>
    

    在 xhtml 中我可以使用 &lt;libtag:training style="blabla" /&gt; 并且我可以在 Renderer 中检索它:

        Map<String, Object> attrMap = component.getAttributes(); // to 
        String style = (String) attrMap.get("style");
    

    【讨论】:

      猜你喜欢
      • 2012-05-21
      • 2015-01-02
      • 1970-01-01
      • 2011-10-15
      • 2011-09-20
      • 2018-02-26
      • 1970-01-01
      • 2011-11-08
      • 1970-01-01
      相关资源
      最近更新 更多