在扩展现有JSF组件的复合组件中继承组件属性 [英] Inheriting component attributes in a composite component which extends an existing JSF component

查看:107
本文介绍了在扩展现有JSF组件的复合组件中继承组件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望扩展以下元素:

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

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

to include code to produce a depressed button:

<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组件吗?因此,我创建了以下内容:

I understand the neatest way to do this is with a JSF component? So I created the following:

<!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>

我的问题是,不必键入 all 可能的属性并映射EL,有没有一种方法可以自动填充它们(例如命令按钮动作和值等)?

My question is, without having to type all the possible attruibutes and map the EL is there a way to populate them automatically (for example the command button action and value etc.)?

推荐答案

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

Unfortunately no, there is no neat way to automagically inherit them this way. You'd really have to redefine them all. For a real custom component, you'd also have to do the same for the .taglib.xml file by the way, so this is not only a problem in composite components, but also in real custom components. Tag attributes do not support any form of inheritance.

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

Consider only redefining those which you absolutely need right now and add new ones on demand only.

这篇关于在扩展现有JSF组件的复合组件中继承组件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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