Hi,
Thank you, every body, for your great help.
But, I have the following snapshot of my Action method:
java.util.ArrayList data=this.applications;
Iterator <FirstObject> it=data.iterator();
String title="";
java.util.ArrayList<Students> students=new java.util.ArrayList();
while(it.hasNext ()) {
FirstObject first=(FirstObject) it.next();
title=first.getCourseTitle();
Student student=selectable.getStudent();
Students.add(student);
…….
…
}
SecondObject second=new SecondObject(title,students…)
In the above, this.application is the list of FirstObjects that comes
from the dataTable. Up to this point I am getting right list.
In the second part, I iterate the list, and get title and students list.
In the third part, I create "second" of SecondObject class, using the
value of title, students from second part.
I am getting the following error:
javax.faces.el.EvaluationException: /pages/applicationProcess.xhtml
@70,126 actionListener="#{applicationProcess.saveStudents}":
java.lang.NullPointerException
com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.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(LifecycleImpl.java:343)
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
note The full stack trace of the root cause is available in the Apache
Tomcat/5.5.17 logs.
Can somebody point me what I am doing wrong? I am using myfaces-1.1.3,
with facelets..
Any pointers would be highly appreciated.
Damar
On 11/11/06, Madhav Bhargava <[EMAIL PROTECTED]> wrote:
Other more elegant way to do it will be to bind the dataTable with a UIData
property in the backing bean.
In the action listener method you can then iterate over the rows easily.
~madhav
> -----Original Message-----
> From: Nebinger, David [mailto:[EMAIL PROTECTED]
> Sent: Friday, November 10, 2006 11:02 PM
> To: MyFaces Discussion
> Subject: RE: Selectable DataTable or similar to that
>
> 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
> >
**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
for the use of the addressee(s). If you are not the intended recipient, please
notify the sender by e-mail and delete the original message. Further, you are
not to copy, disclose, or distribute this e-mail or its contents to any other
person and any such actions are unlawful. This e-mail may contain viruses.
Infosys has taken every reasonable precaution to minimize this risk, but is not
liable for any damage you may sustain as a result of any virus in this e-mail.
You should carry out your own virus checks before opening the e-mail or
attachment. Infosys reserves the right to monitor and review the content of all
messages sent to or from this e-mail address. Messages sent to or from this
e-mail address may be stored on the Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***
--
With regards,
Damar Thapa