Hi Prajakta,
Thanks for the reply.
JSP Page:
<html:select property = "currCourse" onchange="populateField(this)">
<html: option value="0">- Select -</html: option>
<html: optionsCollection name="studentList" label = "studentId" value = "courseName" />
</html:select>
<br />
<br />
<label for="selectedData">Current Course Name:</label>
<html:text property="selectedData" styleId="currCourseName" maxlength="10" readonly="true" disabled="true" />
<br />
<br />
<label for="newCourseName">New Course Name:</label>
<html:text property="newCourseName" styleId="newCourseName" maxlength="15" />
<br />
<br />
=========================
Javascript:
function populateField(obj)
{
document.getElementById("currCourseName").value = obj.value;
}
=================================
Values passed in Action class to update values: Assuming user enters Science in the text field.
newCourseName = Science
selectedData = null
currCourse = Commerce (i.e. whatever use select in the dropdown)
studentId =""
===================================
In Action class to retrieve records from DB on JSP page load i'm doing this:
List<StudentRecord> studentIds= studentDao.fetchStudents();
if(studentIds != null){
studentForm.populateSelect(studentIds);
sess.setAttribute("studentList", studentIds);
}
i'm using session scope's HashMap and using it in JSP page to show studnetIds
=========================================
Here's config file:
<action path="/StudentUpdate" forward="/StudentUpdateCouseName.do" />
<action
path="/StudentUpdate"
type="com.myproject.server.struts.action.StudentUpdateBuildAction"
name="studentUpdateForm"
scope="request"
validate="false"
method = "populateSelect"
input="/pages/mn/StudentUpdateProfile.jsp">
</action>
<action
path="/StudentUpdateSubmit"
type="com.myproject.server.struts.action.StudentUpdateSubmitAction"
name="studentUpdateForm"
scope="request"
validate="true"
input="/pages/mn/StudentUpdateProfile.jsp">
<set-property property="cancellable" value="true"/>
<forward name="cancel" path="/HomePath.do" redirect="true"/>
===============================
Also have a look at populateSelect method of StudentUpdateForm, called from build action to populate hashmap.
public void populateSelect(List<Student> studentIdList){
studentIdList= new HashMap<Integer, String>();
for (Iterator it = studentIdList.iterator(); it.hasNext();) {
Student student= (Student)it.next();
studentIdList.put(student.getStudentId(),student.getCourseName());
}
}
========================
What am i doing wrong? If you need more inputs from my side i'm ready to give.