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
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.
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
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.......
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"));
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.
}
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())
{....}
}>