【问题标题】:a composite component inside panelgrid is not 'expanded'panelgrid 内的复合组件未“扩展”
【发布时间】:2011-09-20 01:12:49
【问题描述】:

基本上,我在 panelgrid 中一次又一次地使用这种模式:

<h:panelGrid columns="2" >
    <h:outputLabel for="heroName" value="Hero Name : " />
    <h:panelGroup>
        <h:inputText label="Hero Name : "
            value="#{ccBean.data.map['heroName']}" id="heroName" />
        <p:message for="heroName" />
    </h:panelGroup>
    ...
</h:panelGrid>

我注意到我重复了很多东西,比如 h:inputText 中的 id,它将在 for="idValue" 中为 outputLabel 再次复制,然后在 p 中再次复制:消息。 inputText 的 label 值和 h:outputLabel 值也会发生同样的情况。

所以,我正在考虑制作一个简单的复合组件来包装它们:

<composite:interface>
    <composite:attribute name="id" required="true" />
    <composite:attribute name="label" required="true" />
    <composite:attribute name="value" required="true" />
    <composite:attribute name="includeLabel" required="false" default="false"/>
</composite:interface>

<composite:implementation>
    <h:outputLabel for="#{cc.attrs.id}" value="#{cc.attrs.label}" 
            render="#{cc.attrs.includeLabel}" />
    <h:panelGroup>
        <h:inputText label="#{cc.attrs.label}"
            value="#{cc.attrs.value}" id="#{cc.attrs.id}" />
        <p:message for="#{cc.attrs.id}" />
    </h:panelGroup>
</composite:implementation>

然后我使用复合组件:

<h:panelGrid columns="2" >
    <s:inputText
        id="heroName"
        label="Hero Name : "
        value="#{ccBean.data.map['heroName']}"
            includeLabel="true"
    />
    <s:inputText
        id="heroName2"
        label="Hero Name 2 : "
        value="#{ccBean.data.map['heroName2']}"
            includeLabel="true"
    />
    ...
</h:panelGrid>

该复合组件工作正常,但 panelGrid 现在假定 s:inputText 是一个组件。使用复合组件之前,一行有2个组件,分别是outputLabel和panelGroup。

在这种情况下是否可以提示复合组件“扩展”自身,以便它在我的 panelGrid 中占用 2 列而不是 1 列?

谢谢!

【问题讨论】:

    标签: jsf jsf-2


    【解决方案1】:

    不,很遗憾没有。最好的办法是创建一个简单的标签文件。

    另见:

    【讨论】:

      猜你喜欢
      • 2011-10-24
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多