Jump to content

Recommended Posts

Posted

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

Posted

<%for(String s:list){%>

<option><%=s%></option>

<%}%>

Posted

Make sure getList() returns values from database. If yes, try to print Object.arraylist in the jsp

Posted

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>

Posted

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>
Posted

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>

 

 

Posted

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  ; 

}

 

Posted

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}" />

Posted

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  ; 

}

 

Posted

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 

Posted

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}" />

 

Posted
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 

 

Posted

did it work?

×
×
  • Create New...