struts2 s:optiontransferselect 标签的使用
在頁面中做數據的導出時候使用。
使用此標簽時一定要在頁面中加入<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 中只能存入對象,在頁面上再接收!
轉載于:https://www.cnblogs.com/java20130726/archive/2010/12/02/3218482.html
總結
以上是生活随笔為你收集整理的struts2 s:optiontransferselect 标签的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android source开发环境搭建
- 下一篇: css框架之960 Grid Syste