gpt4 book ai didi

jsf-2 - JSF2.0-具有可选方法表达式的复合组件

转载 作者:行者123 更新时间:2023-12-04 09:41:07 25 4
gpt4 key购买 nike

我正在实现一个复合组件,但是发现了一个找不到解决方案的问题。

我指定了页面作者无法传递的属性,但是我无法指定方法属性(Action的方法表达式),如果该属性未传递,则复合组件将不使用method属性在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}'

有没有办法做到这一点?

最佳答案

您将必须创建两个p:commandLink元素,并根据参数的定义有条件地呈现它们:

<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>

关于jsf-2 - JSF2.0-具有可选方法表达式的复合组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15420081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com