4

我希望扩展以下元素:

<h:commandButton action="#{menuController.xyz}" value="xyz" 
     image="images/buttons/xyz.png" alt="xyz".....[more attributes]..../>

包括产生按下按钮的代码:

<h:commandButton action="#{menuController.xyz}" value="xyz" 
     image="images/buttons/xyz.png" alt="xyz" 
     onmousedown="[some JS here to change image src]"
     .....[more attributes]..../>

我知道最简洁的方法是使用 JSF 组件?所以我创建了以下内容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:composite="http://java.sun.com/jsf/composite">
    <head>
        <title>Not present in rendered output</title>
    </head>
    <body>
        <composite:interface>
            <composite:attribute name="depressImage" required="false" />
        </composite:interface>

        <composite:implementation>
            <h:commandButton onmousedown="[some JS here to change the img src to the value of #{cc.attrs.depressImage}]" />
        </composite:implementation>
    </body>
</html>

我的问题是,无需输入所有可能的属性并映射 EL,有没有办法自动填充它们(例如命令按钮操作和值等)?

4

1 回答 1

4

不幸的是,没有一种巧妙的方法可以以这种方式自动继承它们。你真的必须重新定义它们。对于真正的自定义组件,顺便说一句,您还必须对.taglib.xml文件执行相同的操作,因此这不仅是复合组件中的问题,而且在真正的自定义组件中也是如此。标签属性不支持任何形式的继承。

考虑只重新定义您现在绝对需要的那些,并仅按需添加新的。

于 2012-08-30T14:02:13.570 回答