【发布时间】:2013-03-03 10:33:41
【问题描述】:
我正在实现一个复合组件,但我发现了一个我没有找到解决方案的问题。
我指定了页面作者可以或不可以传递的属性,但是我无法指定方法属性(Action 的方法表达式),如果未传递,则复合组件不会使用Composite:implementation 标签中的方法属性。
这是我的代码:
<composite:interface>
<composite:attribute name="namePrompt" required="true"/>
<composite:attribute name="actionMethod" method-signature="java.lang.String action()" required="false"/>
<composite:attribute name="showComponent" default="false"/>
</composite:interface>
<composite:implementation>
<div>
<p:commandLink actionListener="#{cc.attrs.actionMethod}"
rendered="#{cc.attrs.showComponent}"
>
<h:outputText value="#{cc.attrs.namePrompt}"/>
</p:commandLink>
</div>
</composite:implementation>
在使用的时候,我没有指定“actionMethod”属性。像这样:
<util:foo namePrompt="SomeName" showComponent="true"/>
但我收到错误消息:
javax.faces.FacesException: Unable to resolve composite component from using page using EL expression '#{cc.attrs.actionMethod}'
有没有办法做到这一点?
【问题讨论】:
-
您可以将可选属性传递给
actionListener。你是什么用例,当actionListener没有被解析并且commandLink被渲染时,你认为应该发生什么? -
是的,链接组件已呈现,但是当链接组件中发生单击操作时,它抱怨我没有为属性 actionMethod 定义方法。但这是我的意图,有时我不想为 actionMethod 属性定义一个动作方法。这可能吗?我认为把'required = false'解决问题。
标签: jsf-2 java-ee-6 composite-component