在JSF 2复合组件中是否存在继承这样的东西? [英] Is there such a thing as inheritance in JSF 2 composite components?

查看:95
本文介绍了在JSF 2复合组件中是否存在继承这样的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSF 2复合组件中是否有继承这样的东西?

Is there such a thing as inheritance in JSF 2 composite components?

据我所知,没有。
我只是确定。

As far as I know, there isn't. I'm just making sure.

谢谢!

推荐答案

复合组件的继承是不可能的。我们为避免代码重复而做的是装饰JSF2复合组件的实现。

Inheritance of composite components is not possible afaik. What we did to avoid code duplication is to decorate the implementation of a JSF2 composite component.

我们的应用程序的所有输入字段共享的东西都在装饰器模板中提供,如这个:

The stuff shared by all input fields of our application is provided within a decorator template like this:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:cc="http://java.sun.com/jsf/composite"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:cu="http://mytags.de/jsftags">

    <!-- provides a common set of layout information for inputfields -->
    <ui:param name ="fieldStyle" value="#{propertiesController.get('FIELD_STYLE', cc.attrs.name)}" />

    <h:panelGroup id="basicInputField" styleClass="basicInputField" layout="block" style="width: #{cc.attrs.width}; height: #{cc.attrs.height};">
        <ui:insert name="component">
            no component given...
        </ui:insert>
    </h:panelGroup>

</ui:composition>

复合组件使用模板来装饰自己:

And the composite component uses the template to decorate itself:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:cu="http://mytags.de/jsftags">

    <cc:interface>
        <cc:attribute name="name" required="true" />
        <cc:attribute name="width" required="false" default="auto" />
        <cc:attribute name="height" required="false" default="auto" />
        <cc:attribute name="inset" required="false" default="0px" />
    </cc:interface>

    <cc:implementation>
        <ui:decorate template="basicInputField.xhtml">
            <ui:define name="component">
                <h:inputText id="inputText" style="#{fieldStyle} width: 100%;" value="#{levelContent.test}" />
            </ui:define>
        </ui:decorate>
    </cc:implementation>
</html>

这样我们只需要更改装饰器模板,当我们获取字段属性的方式时(即只读) ,必需,风格,......)变化。

This way we only need to change the decorator template, when the way we fetch field properties (i.e. readonly, required, style,...) changes.

这篇关于在JSF 2复合组件中是否存在继承这样的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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