<h:selectManyCheckbox>

hi can any one pls tell me ,how to put the data from database in <h:selectManyCheckbox>thanks in advance
[131 byte] By [honey17a] at [2007-11-15]
# 1
Where are you stucking? Look around for h:selectManyListbox examples, the selectManyCheckbox works exactly the same.
BalusCa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 2

hi

iam getting javax.servlet.jsp.JspException: null

<h:selectManyCheckbox id="checkbox" layout="pageDirection"

><f:selectItem value="#{DbRes.group}" />

</h:selectManyCheckbox>

public class DbRes {

private SelectItemGroup group;

int i;

public DbRes( )

{

try

{

Class.forName("com.ibm.db2.jcc.DB2Driver");

Connection con1=DriverManager.getConnection("jdbc:db2://localhost:50000/sam","yyyy","xxx");

con1.setAutoCommit(false);

Statement st1=con1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

ResultSet rs1= st1.executeQuery("Select NUM from ABCD.ACCT");

while(rs1.next())

{

Integer it=new Integer(rs1.getInt(1));

String s=it.toString();

SelectItem items[]=new SelectItem[20];

items=new SelectItem(s);

i++;

setGroup(new SelectItemGroup("numbers", null, false, items));

}

}

catch(Exception e1)

{ }

}

public SelectItemGroup getGroup() {

return group;

}

public void setGroup(SelectItemGroup group {

this.group = group;

}

can you please where did i go wrong

thanks in advance

honey17a at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 3

JSF<h:selectManyCheckbox value="#{myBean.selectedItems}">

<f:selectItems value="#{myBean.selectItems}" />

</h:selectManyCheckbox>

MyBeanprivate List<T> selectedItems;

private List< SelectItem< T, String> > selectItems;

Where T is the Object Type you want to transfer and String is the label.

Some additional notes: 1) don't mix the data and business logic. 2) don't forget to close at least the connection, you're leaking resources otherwise. 3) don't suppress exceptions, throw them or print the trace.

BalusCa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 4

hi BalusC

thanks for ur notes.i will definetely be on that.

iam very new to jsf....so iam confusing alot.....thanks for ur patience in reading and replying to the post. I have some following doubts..

1.I want to add all rows of the column from the database to the selectItems ..

when iam doing so,iam getting only one value that too the last row value.....

can u please tell me how to get all row values to the selectItems

2.another thing is

how to retrive the values of the checkbox which are checked ......and where they are stored....

can u please suggest me what to do.....

thank in advance

honey17a at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 5
1) Retrieve the data from DB and put it in List< SelectItem< T, String > >.2) Those will be set in the selectedItems property of MyBean.
BalusCa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 6

hi BalusC

iam using netbean 5.5,generics doesnt support java 1.4 so i have used SelectItemGroup...

ResultSet rs3= st3.executeQuery("Select MADE from ABCD.CTABLE ");

while (rs3.next())

{

setSelectedValues(new SelectItemGroup("Made",null, false, new SelectItem[]{new SelectItem(rs3.getString("MADE"))}));

}

how to get all rows here.......

honey17a at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 7

Generics isn't required. It just easily shows how the contents should look like. In your case just remove the generic declarations and code accordingly.

List selectItems = new ArrayList();

selectItems.add(new SelectItem(objectToBeSelected, "label"));

BalusCa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 8
hi balusCthanx,checkboxes are displayed from the database,now when the checkboxes are checked ,how to get the data of checked checkboxes so that i can pass to the database
honey17a at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 9

The selected/checked items are available in selectedItems property as is in the examples I gave you above.

public void action() {

// selectedItems is just filled and available here.

}

BalusCa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 10

hi balusC

no data from database is displayed,only column names are displayed.

is this the right way of doing?

int sz=0;

public void action()

{

sz=selectedItems.size();

}

public ResultSet getLloadValues()

{

.......

for(int i=0;i<sz;i++)

{

rs=st.executeQuery("Select * from ABCD.CTABLE where MADE='selectedItems.get(i)' ");

while (rs.next())

{....}

}>

honey17a at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...