MysorePak Posted June 23, 2014 Report Posted June 23, 2014 bhayya eppudu nenu okka query thru list value vathunayi i need to display that list a dropdown list adhi ela cheyaloo asalu arhdam ayithaledhu here is my code Object.setarraylist(getList) public ArrayList getList(){ Connection con = null; PreparedStatement ps = null; ResultSet rs = null; String sql = "SELECT ID FROM TABLE"; ArrayList list = new ArrayList(); try{ con = getConnection(); ps = con.prepareStatement(sql); rs = ps.executeQuery(); while(rs.next()){ list.add(rs.getString("ID")); } }catch (SQLException e){ logger.log(Level.DEBUG, "SQL: " + sql); e.printStackTrace(); }catch (Exception e){ e.printStackTrace(); }finally{ try{ if (ps != null) ps.close(); }catch (Exception e) {} try{ if (!con.isClosed()) con.close(); }catch (Exception e) {} ps = null; con = null; } return list; } In jSP <c:forEach var="list" items="${object.arraylist}" > <option value="<c:out value="${list}"/>"</option> </c:forEach> but dropdown la value display avvadam ledhu
kiran karthik Posted June 23, 2014 Report Posted June 23, 2014 <%for(String s:list){%> <option><%=s%></option> <%}%>
Camaro Posted June 23, 2014 Report Posted June 23, 2014 Make sure getList() returns values from database. If yes, try to print Object.arraylist in the jsp
kiran karthik Posted June 23, 2014 Report Posted June 23, 2014 bhayya eppudu nenu okka query thru list value vathunayi i need to display that list a dropdown list adhi ela cheyaloo asalu arhdam ayithaledhu here is my code Object.setarraylist(getList) public ArrayList getList(){ Connection con = null; PreparedStatement ps = null; ResultSet rs = null; String sql = "SELECT ID FROM TABLE"; ArrayList list = new ArrayList(); try{ con = getConnection(); ps = con.prepareStatement(sql); rs = ps.executeQuery(); while(rs.next()){ list.add(rs.getString("ID")); } }catch (SQLException e){ logger.log(Level.DEBUG, "SQL: " + sql); e.printStackTrace(); }catch (Exception e){ e.printStackTrace(); }finally{ try{ if (ps != null) ps.close(); }catch (Exception e) {} try{ if (!con.isClosed()) con.close(); }catch (Exception e) {} ps = null; con = null; } return list; } In jSP <c:forEach var="list" items="${object.arraylist}" > <option value="<c:out value="${list}"/>"</option> </c:forEach> but dropdown la value display avvadam ledhu i think it should b <option> <c:out value="${list}"/> </option>
kirikiri Posted June 23, 2014 Report Posted June 23, 2014 bhayya eppudu nenu okka query thru list value vathunayi i need to display that list a dropdown list adhi ela cheyaloo asalu arhdam ayithaledhu here is my code Object.setarraylist(getList) public ArrayList getList(){ Connection con = null; PreparedStatement ps = null; ResultSet rs = null; String sql = "SELECT ID FROM TABLE"; ArrayList list = new ArrayList(); try{ con = getConnection(); ps = con.prepareStatement(sql); rs = ps.executeQuery(); while(rs.next()){ list.add(rs.getString("ID")); } }catch (SQLException e){ logger.log(Level.DEBUG, "SQL: " + sql); e.printStackTrace(); }catch (Exception e){ e.printStackTrace(); }finally{ try{ if (ps != null) ps.close(); }catch (Exception e) {} try{ if (!con.isClosed()) con.close(); }catch (Exception e) {} ps = null; con = null; } return list; } In jSP <c:forEach var="list" items="${object.arraylist}" > <option value="<c:out value="${list}"/>"</option> </c:forEach> but dropdown la value display avvadam ledhu <c:forEach var="list" items="${object.arraylist}" > <option><c:out value="${list}"/></option> </c:forEach>
MysorePak Posted June 23, 2014 Author Report Posted June 23, 2014 Try chesa bhayya kani work out avvale.. but i think attribute set cheyale emo.. adhi ela cheyalo teludhi..ekkada set cheyalo telidhu <c:forEach var="list" items="${object.arraylist}" > <option><c:out value="${list}"/></option> </c:forEach>
cherlapalli_jailer Posted June 23, 2014 Report Posted June 23, 2014 if ur using <option then u have to use MAP you can do like this in ur controller class @ModelAttribute("FieldNameList") protected Map referenceData(HttpServletRequest request) throws Exception { //put ur logic here new MAP("",""); return Map ; }
cherlapalli_jailer Posted June 23, 2014 Report Posted June 23, 2014 if ur using <option then u have to use MAP you can do like this in ur controller class @ModelAttribute("FieldNameList") protected Map referenceData(HttpServletRequest request) throws Exception { //put ur logic here new MAP("",""); return Map ; } and in JSP u can use no need for for each etc <form:options items="${FieldNameList}" />
MysorePak Posted June 23, 2014 Author Report Posted June 23, 2014 Okay bhayya edhi use chesthanu and try chestha if ur using <option then u have to use MAP you can do like this in ur controller class @ModelAttribute("FieldNameList") protected Map referenceData(HttpServletRequest request) throws Exception { //put ur logic here new MAP("",""); return Map ; }
cherlapalli_jailer Posted June 23, 2014 Report Posted June 23, 2014 Okay bhayya edhi use chesthanu and try chestha lopa code raayaledu neenu hope u will do it decalare MAP Set the data and return Map and u have to define this as ReferenceData
MysorePak Posted June 23, 2014 Author Report Posted June 23, 2014 Bhayya logic rasthanu but a method ela set cheyali values like i need to pass arguement right.adhi ela rasthamu for setters and in JSP u can use no need for for each etc <form:options items="${FieldNameList}" />
MysorePak Posted June 23, 2014 Author Report Posted June 23, 2014 protected Map referenceData(HttpServletRequest request) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; String sql = "SELECT ID from TABLE"; ArrayList list = new ArrayList(); Map<String, List<String>> map = new HashMap<String, List<String>>(); try{ con = getConnection(); ps = con.prepareStatement(sql); rs = ps.executeQuery(); while(rs.next()){ list.add(rs.getString("ID")); } }catch (SQLException e){ logger.log(Level.DEBUG, "SQL: " + sql); e.printStackTrace(); }catch (Exception e){ e.printStackTrace(); }finally{ try{ if (ps != null) ps.close(); }catch (Exception e) {} try{ if (!con.isClosed()) con.close(); }catch (Exception e) {} ps = null; con = null; } map.put("list", list); return map ; } lopa code raayaledu neenu hope u will do it decalare MAP Set the data and return Map and u have to define this as ReferenceData
Recommended Posts