Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Wiki Markup
{scrollbar}

Handling buttons or links in table rows

If you you have a command link or button in a row of a dataTable, there is an easy way to get to row bean from an javax.faces.event.ActionListener.

Code Block
xml
xml
<h:dataTable value="#{ResultsBean.hitSet.hits}" var="hit">
  <h:column>
    <h:commandLink>
      <f:actionListener type="net.java.OrderActionListener" />
      <h:outputText value="Order" />
    </h:commandLink>
    ...
  </h:column>
</h:dataTable>

By this simple Java code in your subclass of javax.faces.event.ActionListener you get the row bean.

Code Block
java
java
public class OrderActionListener implements ActionListener {

  public void processAction(ActionEvent anEvent) throws AbortProcessingException {

    YourBeanClass tmpBean = null;

    UIComponent tmpComponent = anEvent.getComponent();

    while (null != tmpComponent && !(tmpComponent instanceof UIData)) {
      tmpComponent = tmpComponent.getParent();
    }

    if (tmpComponent != null && (tmpComponent instanceof UIData)) {
      Object tmpRowData = ((UIData) tmpComponent).getRowData();
      if (tmpRowData instanceof YourBeanClass) {
        tmpBean = (YourBeanClass) tmpRowData;

        //TODO Implementation of your method 

      }
    }

    //TODO Exception Handling if UIData not found or tmpRowBean of wrong type

  }
}
Wiki Markup
{scrollbar}