在页面中做数据的导出时候使用。
使用此标签时一定要在页面中加入<s:head/> 原因是此标签和dojo的结合。
login.jsp
<%@ taglib uri="/struts-tags" prefix="s" %>
<head>
<s:head/>
</head>
<s:form action="loginAction" method="post" name="myForm">
<s:optiontransferselect label="选择你喜欢图书"
name="cnbook" leftTitle="中文图书" list="{'struts2权威指南','轻量级javaeye 企业应用空实战','ajax讲义'}"
doubleName="enBook" rightTitle="外文图书" doubleList="{'JavaScrip:The definitive Guide','export one-to-one'}" multiple="true"
addToLeftLabel="向左移动" addToRightLabel="向右移动" addAllToRightLabel="全部右移" addAllToLeftLabel="全部左移"
allowSelectAll="true" headerKey="cnKey" headerValue="选择图书" emptyOption="true" doubleHeaderKey="enKey"
doubleHeaderValue="选择外文图书" doubleMultiple="true" doubleEmptyOption="true" leftDownLabel="向下移动"
rightDownLabel="向下移动"
leftUpLabel="向上移动"
rightUpLabel="向上移动" >
</s:optiontransferselect>
<s:submit value="提交"></s:submit>
</s:form>
loginAction.java
public class LoginAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 8837849417087243469L;
private String userName;
private String email;
private String cnbook;
private String enBook;
@Override
public String execute() throws Exception {
String usrname = getText("username"); // 获取
ActionContext context = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);
String [] cnbooks = request.getParameterValues("cnbook");
for(int i=0;i<cnbooks.length;i++){
System.out.println(" 中文图书 "+cnbooks[i] +"/t");
}
String [] enBooks = request.getParameterValues("enBook");
for(int i=0;i<enBooks.length;i++){
System.out.println(" 中文图书 "+enBooks[i] +"/t");
}
List<Book> lists = new ArrayList<Book>();
Book book1 = new Book(1,"struts2权威指南",20.2);
Book book2 = new Book(2,"轻量级javaeye 企业应用空实战",20.2);
Book book3 = new Book(3,"ajax讲义",20.2);
lists.add(book1);
lists.add(book2);
lists.add(book3);
request.setAttribute("lists", lists);
return SUCCESS;
}
Book.java
public class Book {
private int id;
private String name;
private double money;
public Book() {
}
public Book(int id, String name, double money) {
super();
this.id = id;
this.name = name;
this.money = money;
}
}
success.jsp
<s:optiontransferselect label="选择你喜欢图书"
name="cnbook" leftTitle="中文图书" list="#request.lists" listValue="name" listKey="name"
doubleName="enBook" rightTitle="外文图书" doubleList="{'JavaScrip:The definitive Guide','export one-to-one'}" multiple="true"
addToLeftLabel="向左移动" addToRightLabel="向右移动" addAllToRightLabel="全部右移" addAllToLeftLabel="全部左移"
allowSelectAll="true" headerKey="cnKey" headerValue="选择图书" emptyOption="true" doubleHeaderKey="enKey"
doubleHeaderValue="选择外文图书" doubleMultiple="true" doubleEmptyOption="true">
</s:optiontransferselect>
示例图:
第三图是从后台取出的数据,list 中只能存入对象,在页面上再接收!