大家帮我看看这是怎么回事??
在做Struts2 OptionTransferSelect标签使用练习时,想实现一个“双向选择器”,并找到了一段这样的代码:
1. Action层
TransferSelect.java
package com.mobilesoft.esales.webapp.action;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import
org.apache.log4j.Logger;
public class TransferSelect extends BaseAction {
private static final Logger logger = Logger.getLogger(DoubleListAction.class);
String[] leftRoles;
String[] rightRoles;
public String execute(){
return SUCCESS;
}
public String transferSelect(){
ArrayList<Roles> leftList=new ArrayList<Roles> ();
Roles leftRoles1=new Roles();
leftRoles1.setRoleId(1);
leftRoles1.setRoleName("角色1");
Roles leftRoles2=new Roles();
leftRoles2.setRoleId(2);
leftRoles2.setRoleName("角色2");
Roles leftRoles3=new Roles();
leftRoles3.setRoleId(3);
leftRoles3.setRoleName("角色3");
Roles leftRoles4=new Roles();
leftRoles4.setRoleId(4);
leftRoles4.setRoleName("角色4");
leftList.add(leftRoles1);
leftList.add(leftRoles2);
leftList.add(leftRoles3);
leftList.add(leftRoles4);
ArrayList<Roles> rightList=new ArrayList();
Roles rightRoles1=new Roles();
rightRoles1.setRoleId(1);
rightRoles1.setRoleName("角色5");
Roles rightRoles2=new Roles();
rightRoles2.setRoleId(2);
rightRoles2.setRoleName("角色6");
Roles rightRoles3=new Roles();
rightRoles3.setRoleId(3);
rightRoles3.setRoleName("角色7");
Roles rightRoles4=new Roles();
rightRoles4.setRoleId(4);
rightRoles4.setRoleName("角色8");
rightList.add(rightRoles1);
rightList.add(rightRoles2);
rightList.add(rightRoles3);
rightList.add(rightRoles4);
getRequest().setAttribute("rightList", rightList);
getRequest().setAttribute("leftList", leftList);
return SUCCESS;
}
public String transferSelectPost(){
Map map=getRequest().getParameterMap();
Set set=map.entrySet();
Iterator iterator=set.iterator();
while(iterator.hasNext()){
Map.Entry mapEntry=(Map.Entry)iterator.next();
if(mapEntry.getValue() instanceof String[]){
String[] selectValues=(String[])mapEntry.getValue();
for(int i=0;i<selectValues.length;i++){
logger.fatal("For map test,The key is: "+mapEntry.getKey()+",value is :"+selectValues[i]);
}
}