5

我目前正在创建一个带有可以接受参数的方法签名的 JSF 复合组件。

这是摘录:

<composite:interface>
    ....
    <composite:attribute name="activateHeroMethod" method-signature="java.util.List action(id.co.sofcograha.core.Dto, id.co.sofcograha.core.Dto)" />
</composite:interface>

<composite:implementation>
    ....
    <p:commandLink value="#{hero.map['heroName']}"
        process="@this"
        update="#{cc.attrs.update}"
        oncomplete="infoRaceDialog.hide()"
        image="ui-icon ui-icon-search">
        <f:setPropertyActionListener value="#{hero}"
            target="#{cc.attrs.activateHeroMethod(infoRaceBean.race, hero)}" />
    </p:commandLink>
    ....
</composite:implementation>

target="#{cc.attrs.activateHeroMethod(infoRaceBean.race, hero)}"严重失败,并显示以下错误消息:

javax.faces.view.facelets.TagAttributeException: /resources/sofco/infoRace.xhtml @57,76 target="#{cc.attrs.activateHeroMethod(infoRaceBean.race, hero)}" /resources/sofco/infoRace.xhtml @57,76 target="#{cc.attrs.activateHeroMethod(infoRaceBean.race, hero)}" Illegal attempt to pass arguments to a composite component lookup expression (i.e. cc.attrs.[identifier]).
        at com.sun.faces.facelets.tag.TagAttributeImpl.getValueExpression(TagAttributeImpl.java:401)
        at com.sun.faces.facelets.tag.TagAttributeImpl.getValueExpression(TagAttributeImpl.java:351)
        at com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler.applyAttachedObject(SetPropertyActionListenerHandler.java:128)
        at com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler.apply(SetPropertyActionListenerHandler.java:101)

是否可以从复合组件的属性调用参数化方法?我认为我可以处理多个作为在一种方法中使用多个参数的解决方法,但我不喜欢这种方法,因为它会随着参数的大小而增长。

我可以将每个参数包装到 1 个包装器对象中,但我仍然很好奇是否有办法解决使用多个参数调用方法的问题。

请分享你的想法!

谢谢你。

4

3 回答 3

8

是的,可以这样做,这样做:

<composite:interface displayName="Image uploader with preview list">
        <composite:attribute name="backingBean" required="true" />
        <composite:attribute name="imageType" required="true"  />
</composite:interface>
....
<p:commandButton  value="Save"  actionListener="#{cc.attrs.backingBean.imageUploaded(cc.attrs.imageType)}"/>

希望这有助于一些身体。

于 2012-04-02T16:28:35.033 回答
0

复合组件:

<ui:component
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:cc="http://java.sun.com/jsf/composite"
        xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:p="http://primefaces.org/ui"
>

    <cc:interface>

        <cc:attribute name="header" type="java.lang.String" required="true"/>

        <cc:attribute name="value" required="true"/>
        <cc:attribute name="update" type="java.lang.String" required="false" default=""/>
        <cc:attribute name="controller" required="true"/>

        <cc:attribute name="addLine" required="true" method-signature="void addLine()"/>
        <cc:attribute name="deleteLine" type="java.lang.String" required="true"/>

    </cc:interface>

    <cc:implementation>

        <div id="#{cc.clientId}">

            <p:panel header="#{cc.attrs.header}">

                <p:dataTable id="table" value="#{cc.attrs.value}" var="line">

                    <p:column headerText="#{cc.attrs.header}">
                        <h:outputText value="#{line.entry}"/>
                    </p:column>

                    <p:column width="32">
                        <f:facet name="header">
                            <p:commandButton title="#{msgs.add}" icon="fa fa-plus"
                                             type="button">
                                <f:ajax listener="#{cc.attrs.addLine}" render="#{cc.attrs.update} table"/>
                            </p:commandButton>
                        </f:facet>
                        <p:commandButton title="#{msgs.delete}" icon="fa fa-minus"
                                         type="button">
                            <f:ajax listener="#{cc.attrs.controller[cc.attrs.deleteLine](line)}" render="#{cc.attrs.update} table"/>
                            <p:confirm message="#{msgs.deleteString}" icon="ui-icon-alert"/>
                        </p:commandButton>
                    </p:column>

                </p:dataTable>

            </p:panel>

        </div>

    </cc:implementation>

</ui:component>

Page:

<ui:composition
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
        xmlns:any="http://java.sun.com/jsf/composite/components"
>

    <!--@elvariable id="controller" type="org.controllers.AnyController"-->
    <any:row
            header="#{msgs.subjective}"
            value="#{controller.entity.things}"
            update="form:growl form:save"
            controller="#{anyController}"
            addLine="#{anyController.addTheLine}"
            deleteLine="deleteTheLine"/>

</ui:composition>

Controller:

@javax.inject.Named
@javax.enterprise.context.SessionScoped
public class AnyController
{
    ...

    public void addTheLine()
    {
        ...
    }

    public void deleteTheLine(final Line anyLine)
    {
        ...
    }

    ...
}
于 2017-02-04T20:45:56.387 回答
0

任何有同样问题的人都可以尝试这样的事情

<composite:attribute name="methodName" method-signature="java.lang.String f(java.lang.String, java.lang.String)" required="false" />
于 2018-02-22T13:42:01.443 回答