3

Here my Code from the Composite:

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

I also tried this:

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

But I do get

/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]).

The Method itself looks like this:

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

How can I solve this?

Briefkasten
  • 1,964
  • 2
  • 25
  • 53
  • possible duplicate of [Pass Argument to a composite-component action attribute](http://stackoverflow.com/questions/6355543/pass-argument-to-a-composite-component-action-attribute) – Aritz Oct 14 '13 at 14:34

1 Answers1

2

There's the chance of passing managed bean's reference and method names as separate arguments:

Parent page:

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

Composite:

<!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!");
    }

}

For using arguments with that, here you have a good explanation by @BalusC, which basically implies adding a setPropertyActionListener to your method call, as you cannot combine dynamic method references with on-the-fly arguments:

<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);
}
Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217