Your logic is off; you get the parent but aren't testing it's class before 
casting.  You probably want the code to be:

public void saveStudents(ActionEvent event){
        SelectableApplicant selectableApplicant = null;
        java.util.ArrayList selectableApplicants=null;
                
        UIComponent tmpComponent = event.getComponent();
        
    while (null != tmpComponent && !(tmpComponent instanceof UIData)) {
      tmpComponent = tmpComponent.getParent();
    }

    if (tmpComponent != null) {
      Object tmpRowData = ((UIData) tmpComponent).getRowData();
      if (tmpRowData instanceof SelectableApplicant) {
          selectableApplicant = (SelectableApplicant) tmpRowData;
         selectableApplicants.add(selectableApplicant);

      }
    }

> -----Original Message-----
> From: Damar Thapa [mailto:[EMAIL PROTECTED]
> Sent: Friday, November 10, 2006 11:30 AM
> To: MyFaces Discussion
> Subject: Re: Selectable DataTable or similar to that
> 
> 
> Hi,
> 
> I have the following actionEvent method:
> 
> public void saveStudents(ActionEvent event){
>       SelectableApplicant selectableApplicant = null;
>       java.util.ArrayList selectableApplicants=null;
>               
>       UIComponent tmpComponent = event.getComponent();
>       
>     while (null != tmpComponent && !(tmpComponent instanceof 
> UIData)) {
>       tmpComponent = tmpComponent.getParent();
>       Object tmpRowData = ((UIData) tmpComponent).getRowData();
>       if (tmpRowData instanceof SelectableApplicant) {
>           selectableApplicant = (SelectableApplicant) tmpRowData;
>          selectableApplicants.add(selectableApplicant);
> 
>       }
>     }
> 
> The value of dataTable is applications (a list of SelectableApplicant
> objects).  I am trying to put these object into selectableApplicants
> list.  What I have done wrong here? I am getting following error
> message:
> 
> I get the following error:
> 
> javax.faces.el.EvaluationException: /pages/applicationProcess.xhtml
> @70,126 actionListener="#{applicationProcess.saveStudents}":
> java.lang.ClassCastException: javax.faces.component.html.HtmlPanelGrid
>       
> com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBin
> ding.java:73)
>       javax.faces.component.UICommand.broadcast(UICommand.java:86)
>       
> javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot
> .java:94)
>       
> javax.faces.component.UIViewRoot.processApplication(UIViewRoot
> .java:168)
>       
> org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(L
> ifecycleImpl.java:343)
>       
> org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleIm
> pl.java:86)
>       javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
>       
> org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(Ext
> ensionsFilter.java:144)
> 
> Thanks for all the helps!
> 
> Damar
> 
> 
> On 11/10/06, Gerald Müllan <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > speaking in code, it would be something like this:
> >
> >  public void deleteRow(ActionEvent actionEvent)
> >  {
> >     UIData uiData = JsfUtils.getUIDataParent(actionEvent);
> >     getList().remove(uiData.getRowIndex());
> >  }
> >
> > In JsfUtils:
> >
> > public static UIData getUIDataParent(ActionEvent e)
> >    {
> >        UIComponent component = e.getComponent();
> >
> >        while (component != null && !(component instanceof UIData))
> >        {
> >            component = component.getParent();
> >        }
> >
> >        return (UIData) component;
> >    }
> >
> > cheers,
> >
> > Gerald
> >
> > On 11/10/06, Damar Thapa <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > >
> > >
> > > Sorry to bother you all again!
> > >
> > > What is the command in action event method to get the 
> dataTable's data
> > > so as to manipulate it?
> > >
> > > I will start googling for this tonight.
> > >
> > > Thanks,
> > >
> > > Damar
> > >
> > > On 11/9/06, Damar Thapa <[EMAIL PROTECTED]> wrote:
> > > > Thanks, Simon.
> > > >
> > > > I will try this.
> > > >
> > > > Damar
> > > >
> > > >
> > > > On 11/9/06, Simon Kitching <[EMAIL PROTECTED]> wrote:
> > > > > Hi Damar,
> > > > >
> > > > > I think one way to do this is write a simple class:
> > > > >  public class SelectableApplicant {
> > > > >    private boolean isSelected;
> > > > >    private Applicant applicant;
> > > > >    // add getters/setters for  above
> > > > >  }
> > > > >
> > > > > Change applicationProcess.applicants to return a list of
> > > > > SelectableApplicant rather than Applicant directly.
> > > > >
> > > > > Your JSP columns can be:
> > > > > <h:column>
> > > > >  <t:selectBooleanCheckbox  .. 
> value="#{application.selected}"/>
> > > > > </h:column>
> > > > >
> > > > > <h:column>
> > > > >  <h:outputText value="#{application.applicant.firstName}"/>
> > > > > </h:column>
> > > > >
> > > > > etc.
> > > > >
> > > > > Obviously, you can now iterate over the rows in the 
> data model, checking
> > > > > the boolean flag and if set processing the associated 
> applicant object.
> > > > >
> > > > > Regards,
> > > > >
> > > > > Simon
> > > > >
> > > > > Damar Thapa wrote:
> > > > > > Hi,
> > > > > >
> > > > > > Thanks for your help – truly appreciated.
> > > > > >
> > > > > > Now, I am in the last stage of this problem, ie I 
> have to save the
> > > > > > data from the dataTable into a new file and in new 
> Class structure. It
> > > > > > may be straight forward, anyway, I explain what I 
> am trying to do.
> > > > > > The following is the snapshot of my dataTable:
> > > > > >
> > > > > > <t:dataTable id="applicantsData"
> > > > > > ……
> > > > > > ……
> > > > > > var="application"
> > > > > > value="#{applicationProcess.applications}"
> > > > > > border="1"
> > > > > > preserveDataModel="false">
> > > > > > <h:column>
> > > > > > <f:facet name="header"><h:outputText 
> value="Selected"/></f:facet>
> > > > > > <t:selectBooleanCheckbox  forceId="true" id="chk"
> > > > > > onclick="onChangeSelect(this);"
> > > > > > value="#{applicationProcess.selected}"/>
> > > > > > </h:column>
> > > > > >
> > > > > > <h:column>
> > > > > > <f:facet name="header"><h:outputText value="First 
> Name"/></f:facet>
> > > > > > <h:outputText value="#{application.firstName}"/>
> > > > > > </h:column>
> > > > > >
> > > > > > Surname,
> > > > > > Class
> > > > > > ….
> > > > > >
> > > > > >
> > > > > > </t:dataTable>
> > > > > >
> > > > > > The dataTable is using 
> applicationProcess.applications list, which is
> > > > > > a list of Applicant object.  Applicant Object has 
> firstName, surname,
> > > > > > class, etc. and I have added 
> <t:selectBooleanCheckBox> to determine if
> > > > > > the individual applicants are selected (and its value ie
> > > > > > applicationProcess.selected is not the property of 
> Applicant Class).
> > > > > >
> > > > > > What I have to do is iterate on the rows of 
> dataTable and if the
> > > > > > <selectBooleanCheckbox> is checked, put it in 
> another List. How can I
> > > > > > do this?
> > > > > >
> > > > > > In the following,say:
> > > > > >
> > > > > > public void saveData(ActionEvent event){
> > > > > >
> > > > > > FacesContect context=FacesContext.getCurrentInstance();
> > > > > > List aList=event.getComponent()…..
> > > > > > …..
> > > > > >
> > > > > > In the above, does event returns List from the 
> dataTable?  The value
> > > > > > of <selectBooleanCheckbox> ie 
> applicationProcess.selected is not the
> > > > > > property of <Applicant> class, is it going to be 
> the problem>
> > > > > >
> > > > > >
> > > > > > Any pointers would be highly appreciated, and sorry 
> for lengthy and
> > > > > > too novice questions.
> > > > > >
> > > > > > With regards,
> > > > > >
> > > > > > Damar
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > With regards,
> > > >
> > > > Damar Thapa
> > > >
> > >
> > >
> > > --
> > > With regards,
> > >
> > > Damar Thapa
> > >
> >
> >
> > --
> > http://www.irian.at
> >
> > Your JSF powerhouse -
> > JSF Consulting, Development and
> > Courses in English and German
> >
> > Professional Support for Apache MyFaces
> >
> 
> 
> -- 
> With regards,
> 
> Damar Thapa
> 

Reply via email to