Inheriting component attributes in a composite component which extends an existing JSF component

可紊 提交于 2019-12-04 03:38:30

问题


I wish to extend the following element:

<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]..../>

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>

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.)?


回答1:


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.



来源:https://stackoverflow.com/questions/12197906/inheriting-component-attributes-in-a-composite-component-which-extends-an-existi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!