This week's book giveaways are in the Cloud/Virtualization and Go forums.
We're giving away four copies each of Cloud Native Transformation: Practical Patterns for Innovation and The Go Workshop and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native Transformation: Practical Patterns for InnovationE this week in the Cloud/Virtualization forum
or The Go Workshop in the Go forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Retrieving database values inside the <s:select> tag

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I am able to retrieve database values in my drop down box but not in the manner I want.
1. My employee.jsp is as follows:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<s:form action="AddStudent">
<table border="1" width="80%">
<tr>

<td><s:textfield name="Id" id="Id" value="%{SautoId}" key="SId"/></td>
</tr>
<tr>

<td><s:textfield name="name" id="name" key="SName"/></td></tr>
<tr>

<td><s:textfield name="course" id="course" key="Course" /></td>
<s:select name="DId" value="%{DId}" list="result2"
listkey="DId" label="Designation" >

</s:select>
</tr>
<tr>
<td><s:submit value="ADD"align="center" /></td>
</tr>
</table>
<s:a href="Display.jsp">DISPLAY PAGE</s:a>
</s:form>
</body>
</html>


2. I am getting a list with object values like : com.project.model.StudentVO@7a7a30
com.project.model.StudentVO@2a6a65
com.project.model.StudentVO@4bv67 etc... etc... But I get The exact no. of objects that are there in the datatbase

3. My problem is I am not getting the desired values that are in the database like DES001,DES002,DES003 ....etc...etc...

4. My Action class snippet is as follows :
public String cmbPopulate()
{

IntfStudentBO desgObj = new StudentBO();
result2= desgObj.cmboDid(student1);

if(result2!=null)
{
return SUCCESS;

}
else
{
return ERROR;
}
}



5.My business class snippet :

public List<StudentVO> cmboDid(StudentVO student1) {
List<StudentVO> result= new ArrayList<StudentVO>();
IntfStudentDAO studentDAO = new StudentDAO();
result = studentDAO.cmboDid(student1);
return result;
}
6. My DAO class snippet

public List<StudentVO> cmboDid(StudentVO student1) {
try {
DBConnection dbConnection = new DBConnection();
System.out.println("DATABASE CONNECTED");
try
{

String str= "select D_Id from designation";
String des="";
PreparedStatement ps = dbConnection.getConn().prepareStatement(str);
ResultSet rs =null;
rs=ps.executeQuery();
StudentVO d1;
while (rs.next()) {
d1=new StudentVO();
d1.setDId(rs.getString(1));
des=d1.getDId();
System.out.println("Values of des :"+des);
Slist.add(d1);
}
}
finally{
dbConnection.closeConnection();
}
} catch (SQLException e) {
//TODO Auto-generated catch block
e.printStackTrace();
} catch (NamingException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}

return Slist;
}

Thanks in advance.
Regards,
Piyush N.Sah
 
Ranch Hand
Posts: 333
Scala Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There is a small mistake here in your DAO class




Instead of

Slist.add(d1);
where you are adding the Objects inside the list,

Do
Slist.add(des);
Add values inside the list.


Thanks
-Pankaj Shet
 
piyush sah
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Pankaj for such a quick reply(highly appreciated).But right after I posted this I came up with the solution. & the solution lies in the OGNL...The only slight change that i did to resolve the issue is as followed :
<s:select label="Designation" name="DId" list="result2"
listkey="DId" listValue="DId" value="%{result2.{DId}}" >
</s:select>


P.S. The listValue is DId which is the same as variable DId of my bean class.If The listValue is not entered we'll get no value insise the dropdown.
 
Pankaj Shet
Ranch Hand
Posts: 333
Scala Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great dude
 
That new kid is a freak. Show him this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!