myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "Working_with_DataTable_and_ActionListeners" by LeonardoUribe
Date Fri, 05 Aug 2011 02:43:40 GMT
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
- 
-   }
- }
- }}}
- 

Mime
View raw message