我无法弄清楚如何从multielect中选择多个输入下拉到我的Action.By使用集合而不是array.I已经发布了jsp代码和actionform。
这是我的jsp:
<table class="table-striped" style="width: 100%;">
<tr>
<th style="border: none;"><br><br><br><br><label class="control-label" >Grade</label></th>
<th style="border: none;">
<html:select name="GradeBoardConfigureForm" property="grade" multiple="">
<html:option value="">Grade List</html:option>
<html:optionsCollection name="GradeBoardConfigureForm" property="gradelist" label="grade" value="gradeid"/>
</html:select>
</th>
</tr>
</table>
的FormBean:
public class GradeBoardConfigureForm extends ActionForm {
private String board;
private List grade;
private List gradelist;
private List boardlist;
public String getBoard() {
return board;
}
public void setBoard(String board) {
this.board = board;
}
public List getGradelist() {
gradelist = new ArrayList<>();
DAOFactory factory = HibernateDAOUtil.getDAOFactory();
GradeDao gradedao = factory.getGradeDao();
List<Academicgradeform> gradedaolist = gradedao.list();
gradelist.addAll(gradedaolist);
return gradelist;
}
public void setGradelist(List gradelist) {
this.gradelist = gradelist;
}
public List getBoardlist() {
boardlist = new ArrayList<>();
DAOFactory factory = HibernateDAOUtil.getDAOFactory();
BoardDao boarddao = factory.getBoardDAO();
List<Academicboardform> boarddaolist = boarddao.list();
boardlist.addAll(boarddaolist);
return boardlist;
}
public void setBoardlist(List boardlist) {
this.boardlist = boardlist;
}
public List getGrade() {
return grade;
}
public void setGrade(List grade) {
this.grade = grade;
}
}
答案 0 :(得分:0)
据我所知,这不是直接可能的,并且不是 Struts1哲学。
表单bean应该只是一段有助于在控制器(单例,因此它是无状态)和视图之间传输数据的代码。它不是一个域对象。
所以你的GradeBoardConfigureForm就是你应该不的好例子。你将DAO混合在一个表单bean中。它很难编写并且难以测试,并且会导致代码结构不良。你的问题在这里奠定了。如果您的域对象与表单bean不同,则域对象将具有List,并且DAO层可以将列表绑定到数据库。控制器(stuts1中的Action)将列表复制到表单bean中的Array,将其传递给视图,并且在提交阶段将根据您的需要使用填充的数组。
但我有3个强烈建议: