ksriram
May 19th, 2007, 02:18 AM
Hi,
I want to populate the drop down menu with data from data base on the page load.
I am able to pass the data to the page.But the drop won menu is not populating.
Here is my controller code :
public StateEditController() {
setCommandClass(State.class);
}
protected Object formBackingObject(HttpServletRequest request) throws Exception {
List stateNameList = new ArrayList();
State state = new State();
if(request.getParameter("state_name_eng") != null) {
logger.info("State Name"+request.getParameter("state_name_eng"));
}
else {
logger.info("Inside Else !!!!!!");
//state.getState_name_eng();
stateNameList = editStateModel.editData();
state.setStateList(stateNameList);
}
logger.info("State Name !!!!!!!!!!"+state.getStateList().size());
request.setAttribute("state_name_eng", state.getStateList());
return state;
}
public void setEditStateModel(EditStateModel editStateModel) {
this.editStateModel = editStateModel;
}
And this is my jsp code :
<spring:bind path="command">
<form:select path="state_name_eng" size="1">
<c:forEach items="${command.state}" var="name">
<c:choose>
<c:when test="${not empty name.state_name_eng}" >
<c:out value="${name.state_name_eng}"/>
<br/>
</c:when>
<c:otherwise>
N/A<br/>
</c:otherwise>
</c:choose>
</c:forEach>
</form:select>
</spring:bind>
And is this the right way to go about populating data in the controls while the page is loaded.
Kindly give in ur suggestions.
I want to populate the drop down menu with data from data base on the page load.
I am able to pass the data to the page.But the drop won menu is not populating.
Here is my controller code :
public StateEditController() {
setCommandClass(State.class);
}
protected Object formBackingObject(HttpServletRequest request) throws Exception {
List stateNameList = new ArrayList();
State state = new State();
if(request.getParameter("state_name_eng") != null) {
logger.info("State Name"+request.getParameter("state_name_eng"));
}
else {
logger.info("Inside Else !!!!!!");
//state.getState_name_eng();
stateNameList = editStateModel.editData();
state.setStateList(stateNameList);
}
logger.info("State Name !!!!!!!!!!"+state.getStateList().size());
request.setAttribute("state_name_eng", state.getStateList());
return state;
}
public void setEditStateModel(EditStateModel editStateModel) {
this.editStateModel = editStateModel;
}
And this is my jsp code :
<spring:bind path="command">
<form:select path="state_name_eng" size="1">
<c:forEach items="${command.state}" var="name">
<c:choose>
<c:when test="${not empty name.state_name_eng}" >
<c:out value="${name.state_name_eng}"/>
<br/>
</c:when>
<c:otherwise>
N/A<br/>
</c:otherwise>
</c:choose>
</c:forEach>
</form:select>
</spring:bind>
And is this the right way to go about populating data in the controls while the page is loaded.
Kindly give in ur suggestions.