JSF2.0-具有可选方法表达式的复合组件 [英] JSF2.0 - Composite component with optional method expression
问题描述
我正在实现一个复合组件,但是发现了一个找不到解决方案的问题.
I'm implementing a composite component and I found a issue which I didn't find a solution.
我指定了页面作者无法传递的属性,但是我无法指定方法属性(Action的方法表达式),如果该属性未传递,则复合组件不会使用Composite:implementation标记中的method属性.
I specified its attributes that can or not be passed by the page author, but I couldn't specify a method attribute (a method expression to Action) that, if it wasn't passed, the composite component doesn't use the method attribute in the composite:implementation tag.
这是我的代码:
<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"属性.像这样:
When using it, I didn't specify the "actionMethod" attribute. Like this:
<util:foo namePrompt="SomeName" showComponent="true"/>
但是我收到错误消息:
javax.faces.FacesException: Unable to resolve composite component from using page using EL expression '#{cc.attrs.actionMethod}'
有没有办法做到这一点?
Is there a way to do this?
推荐答案
您将必须创建两个p:commandLink
元素,并根据参数的定义有条件地呈现它们:
You will have to create two p:commandLink
elements and render them conditionally according to definition of your parameter:
<p:commandLink actionListener="#{cc.attrs.actionMethod}" rendered="#{!empty cc.getValueExpression('actionMethod') and cc.attrs.showComponent}">
<h:outputText value="#{cc.attrs.namePrompt}"/>
</p:commandLink>
<p:commandLink rendered="#{empty cc.getValueExpression('actionMethod')}">
<h:outputText value="#{cc.attrs.namePrompt}"/>
</p:commandLink>
这篇关于JSF2.0-具有可选方法表达式的复合组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!