You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2011/08/05 04:43:40 UTC

[Myfaces Wiki] Update of "Working_with_DataTable_and_ActionListeners" by LeonardoUribe

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The "Working_with_DataTable_and_ActionListeners" page has been changed by LeonardoUribe:
http://wiki.apache.org/myfaces/Working_with_DataTable_and_ActionListeners?action=diff&rev1=3&rev2=4

- 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 [[http://java.sun.com/javaee/javaserverfaces/1.1_01/docs/api/javax/faces/event/ActionListener.html|javax.faces.event.ActionListener]].
+ See the updated page on:
  
+ https://cwiki.apache.org/confluence/display/MYFACES/Get+row+data+from+an+ActionListener
- {{{
- <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 [[http://java.sun.com/javaee/javaserverfaces/1.1_01/docs/api/javax/faces/event/ActionListener.html|javax.faces.event.ActionListener]] you get the row bean.
- 
- {{{
- 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
- 
-   }
- }
- }}}
-