Reputation: 661
I have a table and use actionListener to perform delete action see following image. right now i am using event.getComponets() to get value that set from f:param tag. however, in this way, i have to hard code component id in to backing bean. looks like not a good approach. it there a better way to passing value from UI when there is a list of action buttons in table.
final UIParameter parm = (UIParameter) event.getComponent().findComponent(EDIT_SITE_ID_PARM); return (Integer)parm.getValue();
Upvotes: 0
Views: 4794
Reputation: 661
Christian helped find a way by using actionparam. i have put code in following
<a4j:commandButton value="delete" >
<a4j:support event="onclick" reRender="reviewArea">
<a4j:actionparam name="setViewMode" assignTo="#{backingBean.selectTmpId}" value="#{item.id}" actionListener="#{backingBean.viewMsgContent}" />
</a4j:support>
Upvotes: 0
Reputation: 1582
You can use a4j:actionParam name=".." value="..", it works just like f:param but will also do the assignment to bean property automatically. Another option is to use f:setPropertyActionListener.
Upvotes: 1
Reputation: 9621
Your action listener should be like this:
public void deleteActionListener(ActionEvent event) {
final String param = (String) FacesContext
.getCurrentInstance().getExternalContext()
.getRequestParameterMap().get("deleteIdParam");
//convert to int and call your delete method
}
so you only hardcode the parameter's name ant not the component's id.
Of course, now your actionListener will be deleteActionListener instead of your old one.
Upvotes: 0