gpt4 book ai didi

jsf - 通过复合组件传递 MethodParameter

转载 作者:行者123 更新时间:2023-12-04 21:20:19 26 4
gpt4 key购买 nike

这是我的复合代码:

    <cc:attribute name="step" type="Get.Model.Step"/> 
<cc:attribute name="removeQuantityAction" />
[...]
<p:dataList id="quantities" value="#{cc.attrs.Quantities}" var="quantity" itemType="disc">
<com:Quantity removeQuantityAction="#{cc.attrs.removeQuantityAction(cc.attrs[step],quantity)}" />
</p:dataList>

我也试过这个:

removeQuantityAction="#cc.attrs.removeQuantityAction(cc.attrs.step,quantity)}"

但我确实明白了

/resources/Get.comp/Step.xhtml @51,156 removeQuantityAction="#{cc.attrs.removeQuantityAction(cc.attrs.step,quantity)}" /resources/Get.comp/Step.xhtml @51,156 removeQuantityAction="#{cc.attrs.removeQuantityAction(cc.attrs.step,quantity)}" Illegal attempt to pass arguments to a composite component lookup expression (i.e. cc.attrs.[identifier]).

方法本身看起来像这样:

public void removeQuantity(Step step, Quantity quantity) {}

我该如何解决这个问题?

最佳答案

有可能将托管 bean 的引用和方法名称作为单独的参数传递:

父页面:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:my="http://java.sun.com/jsf/composite/emcomp">
<h:head />
<h:body>
<h:form>
<my:myButton value="Send" methodName="send" beanRefer="#{bean}" />
</h:form>
</h:body>
</html>

复合:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html">

<h:body>
<composite:interface>
<composite:attribute name="value" required="true" />
<composite:attribute name="methodName" required="true" />
<composite:attribute name="beanRefer" required="true" />
</composite:interface>

<composite:implementation>
<h:commandButton value="#{cc.attrs.value}"
action="#{cc.attrs.beanRefer[cc.attrs.methodName]}" />
</composite:implementation>
</h:body>
</html>
@ManagedBean
@ViewScoped
public class Bean {

public void send() {
System.out.println("Sent!");
}

}

为了使用参数,here you have @BalusC 的一个很好的解释,它基本上意味着将 setPropertyActionListener 添加到您的方法调用中,因为您不能将动态方法引用与即时参数结合起来:

<h:commandButton value="#{cc.attrs.value}"
action="#{cc.attrs.beanRefer[cc.attrs.methodName]}">
<f:setPropertyActionListener
target="#{cc.attrs.beanRefer[cc.attrs.targetProperty]}"
value="#{cc.attrs.methodArgument}" />
</h:commandButton>
private String targetProperty;

//Getter and setters

public void send() {
System.out.println("Sent " + targetProperty);
}

关于jsf - 通过复合组件传递 MethodParameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19358856/

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