-
1. Re: CommandLink howto use "runtime" value for action/actionListener
christian.yttesen Oct 10, 2012 8:07 AM (in response to christian.yttesen)If I create a binding on the commandLink I somehow need access to the "current" messageAction being iterated - can this be accomplished somehow?.
Tried out a component binding on the commandLink:
<a4j:commandLink binding="#{messageActionBean.actionLink}" />
Added logic in the binding get-method that construct the link + action/actionListener. Current row (MessageAction) was simply obtained by finding the dataTable component (enumerating parents) and invoke the dataTable.getRowData() to get the current row.
public HtmlCommandLink getActionLink() {
MessageAction curr = getCurrentMessageAction(actionLink);
if (actionLink != null && curr != null) {
actionLink.setValue(JsfUtils.getResource(curr.getLink()));
actionLink.setImmediate(true);
if (curr.getActionListener() != null) {
actionLink.addActionListener(curr.getActionListener());
}
if (curr.getAction() != null) {
actionLink.setActionExpression(curr.getAction());
}
}
return actionLink;
}
Seems not to work either - the link is not displayed at all :-(. Might be me not fully understanding component bindings.
Regards,
Christian
-
2. Re: CommandLink howto use "runtime" value for action/actionListener
christian.yttesen Oct 11, 2012 1:30 AM (in response to christian.yttesen)1 of 1 people found this helpfulFound a solution that works for me. Essentially I assign the action and actionListener to the MessageActionBean that holds the list of MessageActions - inside these methods I simply "forward" the calls.
JSF:
<h:commandLink value="#{msgs[item.link]}" actionListener="#{messageActionBean.actionListener}" action="#{messageActionBean.action}" immediate="true">
<f:attribute name="current" value="#{item}" />
<f:setPropertyActionListener value="#{item}" target="#{messageActionBean.current}" />
</h:commandLink>
ManagedBean:
public String action() {
return (String) current.getAction().invoke(FacesContext.getCurrentInstance().getELContext(), null);
}
public void actionListener(ActionEvent evt) {
current = (MessageAction) evt.getComponent().getAttributes().get("current");
current.getActionListener().processAction(evt);
}
Still interessed in hearing about other possible solutions.
Regards,
Christian