【问题标题】:set `action` attribute to a dynamically evaluated string将 `action` 属性设置为动态评估的字符串
【发布时间】:2011-09-11 23:59:09
【问题描述】:

我需要动态设置 commandLink 的操作。

<ice:repeat value="#{mLeft.links}" var="xxx">
    <cvu:leftLink value="#{xxx.value}" action="#{xxx.action}" />
</ice:repeat>

我的自定义标签:

// old
<ui:composition>
    <ice:commandLink immediate="#{immediate}">
        <f:attribute name="action" value="#{action}" />
        <f:attribute name="actionListener" value="#{actionListener}" />
        <f:attribute name="value" value="#{value}" />
    </ice:commandLink>
</ui:composition>

但它似乎不起作用。
过去,我使用反射解决了类似的问题。没有更简单的解决方案吗?
我正在使用 Facelets 和 JSF 2.0。

编辑:

好的。我将 UI 组件更改为 JSF 2.0 复合组件,但仍然无法使其工作。它仅在我使用方法调用自定义组件时才有效,并且它被重新定位到我的自定义组件中的链接。
我想要的是能够生成一个链接列表,每个链接都调用我作为 String 提供的方法!
关于&lt;cc:actionSource我看到它只用于&lt;f:actionListener for="xxx" binding="" /&gt;
请帮忙。

// new one
<cc:interface>
    <cc:attribute name="action" required="true" targets="actiune" />
    <cc:attribute name="immediate" required="false" default="false" />
    <cc:attribute name="value" required="true" />
    <cc:actionSource name="ok" targets="actiune" />
</cc:interface>
<cc:implementation>
    <ice:graphicImage value="/images/pucemenu.gif" alt="right"
        style="vertical-align: middle; margin-left: 13px;" />
    <ice:commandLink id="actiune" immediate="#{cc.attrs.immediate}"
        value="#{cc.attrs.value}">
    </ice:commandLink>
</cc:implementation>

【问题讨论】:

  • 您使用的是复合组件吗?如果是这样,您可以在您的合成界面中使用 标签。
  • 我没有使用 JSF 2.0 中的复合组件,而是从 Facelets 创建自定义组件。但是如果可以的话,我可以从 JSF 2.0 切换到复合组件。你能给我举个例子吗?谢谢

标签: jsf attributes components action facelets


【解决方案1】:

所以目前还不支持这样的东西。

【讨论】:

    【解决方案2】:

    要么传递 bean:

    <ice:repeat value="#{mLeft.links}" var="xxx">
        <cvu:leftLink bean="#{xxx}" value="value" action="action" />
    </ice:repeat>
    

    <ui:composition>
        <ice:commandLink value="#{bean[value]}" action="#{bean[action]}" />
            ...
    </ui:composition>
    

    如果您使用固定值属性和操作方法名称,您甚至可以完全省略它们并单独传递 bean:

    <ice:repeat value="#{mLeft.links}" var="xxx">
        <cvu:leftLink bean="#{xxx}" />
    </ice:repeat>
    

    <ui:composition>
        <ice:commandLink value="#{bean.value}" action="#{bean.action}" />
            ...
    </ui:composition>
    

    或者,使用复合组件,其中您将操作定义为&lt;cc:attribute method-signature&gt;):

    <cc:interface>
        <cc:attribute name="action" method-signature="java.lang.String action()" />
        ...
    </cc:interface>
    <cc:implementation>
        <ice:commandLink value="#{cc.attrs.value}" action="#{cc.attrs.action}" />
        ...
    </cc:implementaiion>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多