You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Caroline Jen <ji...@yahoo.com> on 2007/05/25 20:54:20 UTC

JSF Table - How to Clean-up Previous Selections

I am doing something very basic. 

First, I display my 1stTable with a checkbox for each
row (no problem). My DepartureManagementBean.java read
the user selected rows and prepare for displaying my
2ndTable without checkbox for each row. My 2ndTable
displays only the rows that are selected from the
1stTable.

I can display the 2ndTable. But, the problem is that
if I re-visit the 1stTable and make another round of
selections, the new selections get append to the
previous selections and all of them are displayed in
the 2ndTable.

I know I have to do some clean-up but my attempts have
been unsuccessful. Please advise.

DepartureManagementBean:
[code]
package processAction;
 
import java.util.ArrayList;
import java.util.List;
import processDelegate.ListPersonnel;
import processDelegate.PersonnelBean;
 
public class DepartureManagementBean 
{
    private List personnel = new ArrayList();
    private List departurePersonnel = new ArrayList();
    
    public DepartureManagementBean()
    {
   
    	// instantiate the business delegate
    	ListPersonnel listPersonnel = new
ListPersonnel();
    	personnel = listPersonnel.getPersonnelInfo();
 
    }
 
	/**
	 * @return Returns the personnel.
	 */
	public List getPersonnel() 
	{
		return personnel;
	}
	/**
	 * @param personnel The personnel to set.
	 */
	public void setPersonnel( List personnel ) 
	{
		this.personnel = personnel;
	}
 
	public String updateDeparturePersonnel() 
	{
        // iterate through the data rows ...
        for ( int index = 0; index < personnel.size();
index++ ) 
        {
        	PersonnelBean personnelBean = ( PersonnelBean
)personnel.get( index );
	 
	            // If this row is selected, add all data
fields the corresponding message
	            if ( personnelBean.isSelectedPersonnel()
)
	            {
	                departurePersonnel.add( personnelBean
);
	            }
        }
        return "success";
	}
	
	/**
	 * @return Returns the departurePersonnel.
	 */
    public List getDeparturePersonnel() 
    {
      return departurePersonnel;
    }
	/**
	 * @param departurePersonnel The departurePersonnel
to set.
	 */
    public void setDeparturePersonnel( List
departurePersonnel ) 
    {
      this.departurePersonnel = departurePersonnel;
    }
	
}// End DepartureManagementBean.java
[/code]



       
____________________________________________________________________________________Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. 
http://mobile.yahoo.com/go?refer=1GNXIC

Re: JSF Table - How to Clean-up Previous Selections

Posted by Caroline Jen <ji...@yahoo.com>.
Thanks very much.

departurePersonnel.clear();
does the job.
--- Mike Kienenberger <mk...@gmail.com> wrote:

> Yes, that's probably a better strategy than what I
> suggested.  My
> suggestion won't correctly clear out duplicate items
> that are already
> selected.
> 
> On 5/25/07, Volker Weber <v....@inexso.de> wrote:
> > or just a
> >
> > 2007/5/25, Mike Kienenberger <mk...@gmail.com>:
> > > On 5/25/07, Caroline Jen <ji...@yahoo.com>
> wrote:
> > >
> > > >         public String
> updateDeparturePersonnel()
> > > >         {
> >
> >   departurePersonnel.clear();
> >
> >
> > at this point?
> >
> >
> > > >         // iterate through the data rows ...
> > > >         for ( int index = 0; index <
> personnel.size();
> > > > index++ )
> > > >         {
> > > >                 PersonnelBean personnelBean =
> ( PersonnelBean
> > > > )personnel.get( index );
> > > >
> > > >                     // If this row is
> selected, add all data
> > > > fields the corresponding message
> > > >                     if (
> personnelBean.isSelectedPersonnel()
> > > > )
> > > >                     {
> > > >                        
> departurePersonnel.add( personnelBean
> > > > );
> > > >                     }
> > > >         }
> > > >         return "success";
> > > >         }
> > >
> > >
> > > Is this what you're asking for?
> > >
> > > if ( personnelBean.isSelectedPersonnel() )
> > > {
> > >     departurePersonnel.add( personnelBean);
> > > }
> > > else
> > > {
> > >     departurePersonnel.remove( personnelBean);
> > > }
> > >
> >
> 



      ____________________________________________________________________________________Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 


Re: JSF Table - How to Clean-up Previous Selections

Posted by Mike Kienenberger <mk...@gmail.com>.
Yes, that's probably a better strategy than what I suggested.  My
suggestion won't correctly clear out duplicate items that are already
selected.

On 5/25/07, Volker Weber <v....@inexso.de> wrote:
> or just a
>
> 2007/5/25, Mike Kienenberger <mk...@gmail.com>:
> > On 5/25/07, Caroline Jen <ji...@yahoo.com> wrote:
> >
> > >         public String updateDeparturePersonnel()
> > >         {
>
>   departurePersonnel.clear();
>
>
> at this point?
>
>
> > >         // iterate through the data rows ...
> > >         for ( int index = 0; index < personnel.size();
> > > index++ )
> > >         {
> > >                 PersonnelBean personnelBean = ( PersonnelBean
> > > )personnel.get( index );
> > >
> > >                     // If this row is selected, add all data
> > > fields the corresponding message
> > >                     if ( personnelBean.isSelectedPersonnel()
> > > )
> > >                     {
> > >                         departurePersonnel.add( personnelBean
> > > );
> > >                     }
> > >         }
> > >         return "success";
> > >         }
> >
> >
> > Is this what you're asking for?
> >
> > if ( personnelBean.isSelectedPersonnel() )
> > {
> >     departurePersonnel.add( personnelBean);
> > }
> > else
> > {
> >     departurePersonnel.remove( personnelBean);
> > }
> >
>

Re: JSF Table - How to Clean-up Previous Selections

Posted by Volker Weber <v....@inexso.de>.
or just a

2007/5/25, Mike Kienenberger <mk...@gmail.com>:
> On 5/25/07, Caroline Jen <ji...@yahoo.com> wrote:
>
> >         public String updateDeparturePersonnel()
> >         {

  departurePersonnel.clear();


at this point?


> >         // iterate through the data rows ...
> >         for ( int index = 0; index < personnel.size();
> > index++ )
> >         {
> >                 PersonnelBean personnelBean = ( PersonnelBean
> > )personnel.get( index );
> >
> >                     // If this row is selected, add all data
> > fields the corresponding message
> >                     if ( personnelBean.isSelectedPersonnel()
> > )
> >                     {
> >                         departurePersonnel.add( personnelBean
> > );
> >                     }
> >         }
> >         return "success";
> >         }
>
>
> Is this what you're asking for?
>
> if ( personnelBean.isSelectedPersonnel() )
> {
>     departurePersonnel.add( personnelBean);
> }
> else
> {
>     departurePersonnel.remove( personnelBean);
> }
>

Re: JSF Table - How to Clean-up Previous Selections

Posted by Mike Kienenberger <mk...@gmail.com>.
On 5/25/07, Caroline Jen <ji...@yahoo.com> wrote:

>         public String updateDeparturePersonnel()
>         {
>         // iterate through the data rows ...
>         for ( int index = 0; index < personnel.size();
> index++ )
>         {
>                 PersonnelBean personnelBean = ( PersonnelBean
> )personnel.get( index );
>
>                     // If this row is selected, add all data
> fields the corresponding message
>                     if ( personnelBean.isSelectedPersonnel()
> )
>                     {
>                         departurePersonnel.add( personnelBean
> );
>                     }
>         }
>         return "success";
>         }


Is this what you're asking for?

if ( personnelBean.isSelectedPersonnel() )
{
    departurePersonnel.add( personnelBean);
}
else
{
    departurePersonnel.remove( personnelBean);
}