we have a (in our oppinion) very simple scenario here. But we got stuck somehow on composite components and f:attribute tags. I'll try to keep the code as simple as possible.
Composite Component:
<cc:interface name="button">
...
<cc:attribute
name="actionListener"
required="true"
method-signature="void f(javax.faces.event.ActionEvent)"
target="button"
shortDescription="The action listener for this button." />
...
</cc:interface>
<cc:implementation>
<ice:commandButton
...
actionListener="#{cc.attrs.actionListener}"
...>
<cc:insertChildren />
</ice:commandButton>
</cc:implementation>
... now we use the component like this:
<ctrl:button
...
actionListener="#{bean.method}"
...>
<f:attribute name="objectId" value="#{someObject.id}" />
</ctrl:button>
Now we need to access the "objectId" attribute inside the action listener method. We already tried somethign like this:
public void method(ActionEvent event)
{
...
event.getComponent().getAttributes().get("objectId");
...
}
But the attribute map doesn't contain the objectId. Is there anything wrong on this approach? What is the recommended way to solve this problem?
Would be nice if someone could help us out.
Thanks! SlimShady
This <f:attribute>
hack is a leftover from JSF 1.0/1.1 when it was not possible to pass objects as additional arguments to command buttons/links. Since JSF 1.2 you are supposed to use <f:setPropertyActionListener>
for this.
<ctrl:button action="#{bean.method}">
<f:setPropertyActionListener target="#{bean.objectId}" value="#{someObject.id}" />
</ctrl:button>
Since EL 2.2 (which is standard part of Servlet 3.0 but is for Servlet 2.5 implementable with help of JBoss EL) you could instead even pass the whole object just as method argument:
<ctrl:button action="#{bean.method(someObject.id)}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With