I have create a data table "A" based on a List. To
create this data table "A" with a checkbox in each row
of the table, I specify the following:
a. managed-bean-class: packageName.ListAction
b. managed-bean-name: listAction
c. The List is called "personnel".
d. The properties of the PersonnelBean are the columns
of data Table.
e. I have a "selected" boolean property on the
PersonnelBean that can be used to mark which persons
have been selected.
I am going to submit all the data in table "A",
iterate through all the rows and create another List
based on marked checkboxes. And I have four questions
regarding how to process the data. My questions are
embedded in the code below. For display ing the next
data table "B" that contains all the selected records
of data table "A":
a. managed-bean-class: packageName.SelectAction.
b. managed-bean-name: selectAction
c. The List to be created is called "departPersonnel"
[code]
import ....
public class SelectAction
{
List departPersonnel = null;
public SelectAction()
{
SelectDelegate sd = new SelectDelegate();
// Question 1. Should I put the next two line
of code here?
// or I should put the
next two line of code in the
// SelectDelegate
class and call the
//
updateDepartPersonnel()
// method of that class
without supplying a parameter?
DataModel personnelData =
ListAction().getPersonnel();
List personnel =
(List)personnelData.getWrappedData();
departPersonnel = sd.updateDepartPersonnel(
personnel );
}
// Question 2. A bean should have an empty
constructor and a pair of
// get and set methods for
each of its properties. I
// certainly do not have an
empty constructor. What is the
// correct way of doing it?
public List getDepartPersonnel()
{
return this.departPersonnel;
}
public void setDepartPersonnel( List data )
{
this departPersonnel= data;
}
}
[/code]
[code]
import .....
public class SelectDelegate
{
List departPersonnel = null;
// Method to update all the selected personnel
records
public List updateDepartPersonnel()
{
DataModel personnelData =
ListAction().getPersonnel();
List personnel =
(List)personnelData.getWrappedData();
// Iterate through the data rows ...
int first = 0;
int rows = personnel.size();
for (int index = first; index < (first +
rows); index++)
{
// Question 3. Does the statement below
obtain all the properties
// of a particular
row?
PersonnelBean personnelBean =
(PersonnelBean)personnel.get(index);
// If this row is selected, add all data
fields the corresponding personnel information
// Question 4. The "selected" is the
boolean property of the
// PersonnelBean.
Should I code
// if
(personnelBean.selected) { ... } instead?
if (personnelBean.isSelected())
{
departPersonnel.add( personnelBean );
}
}
return departPersonnel;
}
[/code]
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs