You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by JavaNoobie87 <vi...@enzentech.com> on 2011/03/14 05:52:37 UTC
loading Dropdown dynamically from database
Hi All,
Im developing a Crud example using Struts 2 where im in the need to load
values for a dropdown box dynamically from a database . However im just
getting a empty dropdown now .
The JSP code snippet is as below.
DomainType
The action class and DAO for the same function are as below.
Action.
public String loadDomainType(){
// Class used to get the domaintype from domaintype table
System.out.println("my logging statement");
String result=SUCCESS;
try {
System.out.println("Inside loaddomaintype");
List loadDomainType = DomainDAO.loadDomainType();
dtList=loadDomainType;
} catch (Exception e) {
// TODO Auto-generated catch block;
result=ERROR;
e.printStackTrace();
}
DAO Class--
public static List loadDomainType() throws Exception {
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
System.out.println("loadDomaintype DAO");
DomainBean bean = new DomainBean();
ArrayList dtList = new ArrayList();
try {
con= DBConnector.getConnection();
if (con != null){
System.out.println("Connected");
String query= " SELECT CODE,DESCRIPTION,OBJECTID FROM DOMAINTYPE " ;
stmt = con.prepareStatement(query);
rs = stmt.executeQuery();
System.out.println("inside loadDomainType");
while (rs.next()){
bean.setCode(rs.getString("CODE"));
bean.setDescription(rs.getString("DESCRIPTION"));
bean.setObjid(rs.getInt("OBJECTID"));
dtList.add(bean);
}
}
} catch (SQLException sqe) {
sqe.printStackTrace();
} finally {
DBConnector.closeResultSet(rs);
DBConnector.closeStatement(stmt);
DBConnector.closeConnection(con);
}
return dtList;
}
--
View this message in context: http://struts.1045723.n5.nabble.com/loading-Dropdown-dynamically-from-database-tp3555884p3555884.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: loading Dropdown dynamically from database
Posted by Brian Thompson <el...@gmail.com>.
Oh, nevermind -- I replied before I saw that you'd solved that part of it :/
-Brian
On Tue, Mar 15, 2011 at 2:40 AM, JavaNoobie87 <vi...@enzentech.com>wrote:
> Following changes? I didnt get what you meant. i dont see any code :S
>
> --
> View this message in context:
> http://struts.1045723.n5.nabble.com/loading-Dropdown-dynamically-from-database-tp3555885p3683230.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: loading Dropdown dynamically from database
Posted by JavaNoobie87 <vi...@enzentech.com>.
Following changes? I didnt get what you meant. i dont see any code :S
--
View this message in context: http://struts.1045723.n5.nabble.com/loading-Dropdown-dynamically-from-database-tp3555885p3683230.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: loading Dropdown dynamically from database
Posted by Brian Thompson <el...@gmail.com>.
Try making the following changes to your Java code -- the output should give
you some clues about what's going wrong.
-Brian
On Sun, Mar 13, 2011 at 11:52 PM, JavaNoobie87 <vi...@enzentech.com>wrote:
> Hi All,
> Im developing a Crud example using Struts 2 where im in the need to load
> values for a dropdown box dynamically from a database . However im just
> getting a empty dropdown now .
> The JSP code snippet is as below.
> DomainType
>
>
>
> The action class and DAO for the same function are as below.
>
> Action.
> public String loadDomainType(){
> // Class used to get the domaintype from domaintype table
> System.out.println("my logging statement");
> String result=SUCCESS;
> try {
> System.out.println("Inside loaddomaintype");
> List loadDomainType = DomainDAO.loadDomainType();
> dtList=loadDomainType;
>
System.out.println("dtList length: " + dtList.length);
> } catch (Exception e) {
> // TODO Auto-generated catch block;
> result=ERROR;
> e.printStackTrace();
> }
>
> DAO Class--
> public static List loadDomainType() throws Exception {
> Connection con = null;
> PreparedStatement stmt = null;
> ResultSet rs = null;
> System.out.println("loadDomaintype DAO");
> DomainBean bean = new DomainBean();
> ArrayList dtList = new ArrayList();
>
> try {
> con= DBConnector.getConnection();
> if (con != null){
> System.out.println("Connected");
> String query= " SELECT
> CODE,DESCRIPTION,OBJECTID FROM DOMAINTYPE " ;
> stmt = con.prepareStatement(query);
> rs = stmt.executeQuery();
> System.out.println("inside loadDomainType");
> while (rs.next()){
>
bean = new DomainBean();
> bean.setCode(rs.getString("CODE"));
>
> bean.setDescription(rs.getString("DESCRIPTION"));
>
> bean.setObjid(rs.getInt("OBJECTID"));
> dtList.add(bean);
>
System.out.println("Adding bean to list: " + bean.getDescription());
>
>
> }
>
> }
> } catch (SQLException sqe) {
> sqe.printStackTrace();
>
> } finally {
> DBConnector.closeResultSet(rs);
> DBConnector.closeStatement(stmt);
> DBConnector.closeConnection(con);
> }
>
> return dtList;
> }
>
>
> --
> View this message in context:
> http://struts.1045723.n5.nabble.com/loading-Dropdown-dynamically-from-database-tp3555884p3555884.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>