3

这是我的综合代码:

    <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)}" 非法尝试将参数传递给复合组件查找表达式(即 cc.attrs.[identifier])。

方法本身如下所示:

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

我该如何解决这个问题?

4

1 回答 1

1

有可能将托管 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!");
    }

}

对于使用参数, @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);
}
于 2013-10-14T14:21:32.057 回答