-1

JSF 1.2 DataTable

I know how to remove the row from datatable writing following code.

jsp

<h:graphicImage id="deleteRowBtn_img" url="../../images/table_icon_delete.gif" style="cursor:pointer" alt="Delete Row">
    <a4j:support id="deleteRowBtn" event="onclick"  actionListener="#{mnpAction.deleteMultiNoPortRow}" reRender="multiNoPortTable" oncomplete="resetViewConfigs();"/>
</h:graphicImage>

action bean

public void deleteMultiNoPortRow(ActionEvent ae) {
    {
        int index = abcBean.getDataTable().getRowIndex();
        mnpBean.getMultiNoPortingList().remove(index);
    }
}

But i want to know is there any other way to remove row from datatable in JSF1.2. Any help regarding this appreciate!!!!!!

prageeth
  • 7,159
  • 7
  • 44
  • 72
seeker
  • 79
  • 2
  • 16
  • remove the item from the list in the backing bean of your `` or `` and rerender (update) your table after the action. – Luiggi Mendoza Dec 13 '12 at 13:36
  • @prageeth thanks for reply.How i identify particular object remove from list in backing bean?? – seeker Dec 13 '12 at 13:49
  • It was me, not prageeth. Look for a tutorial on JSF DataTable like [Using datatables](http://balusc.blogspot.com/2006/06/using-datatables.html) from BalusC. Next time, please come with a specific question instead of *how can I do the foo that can be answered by googling*? – Luiggi Mendoza Dec 13 '12 at 13:57

1 Answers1

0

You can get the same appearance and functionality by using an a4j:commandButton and its image attribute instead of <h:graphicImage> as below.

<a4j:commandButton image="../../images/table_icon_delete.gif" actionListener="#{mnpAction.deleteMultiNoPortRow}"/>


If your <h:graphicImage> is in a column of the table, you can pass the var of the table to a method in your baking bean and remove that element from the list without having to use the row index. Here use action instead of actionListener.

<a4j:support id="deleteRowBtn" event="onclick" action="#{mnpAction.remove(myVar)}".../>

In mnpAction bean (Assuming the type of your list is T)

public void remove(T s) {
   mnpBean.getMultiNoPortingList().remove(s);
}

Edit:
Since you are using JSF1.2 you may not use #{mnpAction.remove(myVar)}" to pass parameters to the bean if you don't like to upgrade your EL library.

prageeth
  • 7,159
  • 7
  • 44
  • 72
  • The question is for JSF 1.2. Please tell OP that he/she must upgrade the EL library in order to send parameters through the action method call. – Luiggi Mendoza Dec 13 '12 at 14:00
  • Indeed, the JSF 1.2 way would be to pass a paratemer to the commandButton or commandLink (h or a4j) using `` or ``. You should check the link posted in my comment on OP's question about working with datatables, by BalusC. – Luiggi Mendoza Dec 13 '12 at 14:52