1. 示例

action 注入数据 和 处理action

/**
 * OgnlAction
 */
public class UiAction extends ActionSupport {
	private static final long serialVersionUID = -6933309304624396640L;
	
	/* 婚否 */
	private boolean married = true;
	/* javabean集合 */
	private List userList;
	
	/*省集合*/
	private List<Area> provinces ;
	
	/* 选中的id */
	private Integer selectedId = 10;

	public List getUserList() {
		return userList;
	}

	public void setUserList(List userList) {
		this.userList = userList;
	}

	public String reg() {
		popUserList();
		return "success";
	}

	public String toRegView() {
		System.out.println("toRegView");
		return "loginView";
	}
	
	/**
	 * 保存数据,
	 */
	public String saveData(){
		popUserList();
		popProvinces();
		return "showView" ;
	}
	
	/**
	 * 组装用户集合
	 */
	private void popUserList(){
		userList = new ArrayList<User>();
		User u = null ;
		for(int i = 0 ; i < 10 ; i ++){
			u = new User();
			u.setId(1 + i);
			u.setName("tom" + i);
			u.setAge(20 + i);
			userList.add(u);
		}
	}
	
	/**
	 * 组装province集合数组
	 */
	private void popProvinces(){
		provinces = new ArrayList<Area>();
		Area p1 = new Area(1,"1号省");
		p1.getCities().add(new Area(11,"1.1城市"));
		p1.getCities().add(new Area(12,"1.2城市"));
		p1.getCities().add(new Area(13,"1.3城市"));
		
		Area p2 = new Area(2,"2号省");
		p2.getCities().add(new Area(21,"2.1城市"));
		p2.getCities().add(new Area(22,"2.2城市"));
		p2.getCities().add(new Area(23,"2.3城市"));
		provinces.add(p1);
		provinces.add(p2);
	}

	public boolean isMarried() {
		return married;
	}

	public void setMarried(boolean married) {
		this.married = married;
	}

	public Integer getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(Integer selectedId) {
		this.selectedId = selectedId;
	}

	public List<Area> getProvinces() {
		return provinces;
	}

	public void setProvinces(List<Area> provinces) {
		this.provinces = provinces;
	}
}

showview.jsp

reg.jsp


关联选择 area 区域类

package cn.itcast.struts2.model;

import java.util.ArrayList;
import java.util.List;

/**
 * 区域类
 */
public class Area {
	private Integer id ;
	private String areaName ;
	private String areaNo ;
	private int type ;
	
	/* 省所属城市集合 */
	private List<Area> cities = new ArrayList<Area>();
	
	public Area(Integer id, String areaName) {
		this.id = id;
		this.areaName = areaName;
	}
	
	public Area(Integer id, String areaName, String areaNo) {
		this.id = id;
		this.areaName = areaName;
		this.areaNo = areaNo;
	}
	
	public Area(Integer id, String areaName, String areaNo, int type) {
		this.id = id;
		this.areaName = areaName;
		this.areaNo = areaNo;
		this.type = type;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getAreaName() {
		return areaName;
	}
	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}
	public String getAreaNo() {
		return areaNo;
	}
	public void setAreaNo(String areaNo) {
		this.areaNo = areaNo;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}

	public List<Area> getCities() {
		return cities;
	}

	public void setCities(List<Area> cities) {
		this.cities = cities;
	}
}


<s:doubleselect /> 产生的级联菜单是换行的, 可通过如下方式解决 s:doubleselect 换行的问题。

<style type="text/css">

    .nobr br{display:none;}

</style>

 

在有s:doubleselect 的 s:form 表单上套上div

<div class="nobr">

    <s:form>    ......     </s:form>

</div>
http://blog.csdn.net/shangpusp/article/details/4956011
 

相关文章:

  • 2021-09-29
  • 2021-12-08
  • 2021-04-21
  • 2021-08-26
猜你喜欢
  • 2022-01-07
  • 2022-12-23
  • 2021-10-12
  • 2021-06-01
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案