`
兩ting
  • 浏览: 75316 次
  • 性别: Icon_minigender_2
  • 来自: 成都
社区版块
存档分类
最新评论

flex学习之联动下拉框实现

    博客分类:
  • flex
阅读更多
Java代码 复制代码 收藏代码
  1. TbArea.java
  2. package com.zn.entity;
  3. import java.util.HashSet;
  4. import java.util.Set;
  5. /**
  6. * TbArea entity.
  7. *
  8. * @author MyEclipse Persistence Tools
  9. */
  10. public class TbArea implements java.io.Serializable {
  11. // Fields
  12. private String areaCode;
  13. private String areaName;
  14. private String parentAreaCode;
  15. private String root;
  16. private Short zone;
  17. private String navigateUrl;
  18. private Short areaType;
  19. private Set usercustems = new HashSet(0);
  20. // Constructors
  21. /** default constructor */
  22. public TbArea() {
  23. }
  24. /** full constructor */
  25. public TbArea(String areaName, String parentAreaCode, String root,
  26. Short zone, String navigateUrl, Short areaType, Set usercustems) {
  27. this.areaName = areaName;
  28. this.parentAreaCode = parentAreaCode;
  29. this.root = root;
  30. this.zone = zone;
  31. this.navigateUrl = navigateUrl;
  32. this.areaType = areaType;
  33. this.usercustems = usercustems;
  34. }
  35. // Property accessors
  36. public String getAreaCode() {
  37. return this.areaCode;
  38. }
  39. public void setAreaCode(String areaCode) {
  40. this.areaCode = areaCode;
  41. }
  42. public String getAreaName() {
  43. return this.areaName;
  44. }
  45. public void setAreaName(String areaName) {
  46. this.areaName = areaName;
  47. }
  48. public String getParentAreaCode() {
  49. return this.parentAreaCode;
  50. }
  51. public void setParentAreaCode(String parentAreaCode) {
  52. this.parentAreaCode = parentAreaCode;
  53. }
  54. public String getRoot() {
  55. return this.root;
  56. }
  57. public void setRoot(String root) {
  58. this.root = root;
  59. }
  60. public Short getZone() {
  61. return this.zone;
  62. }
  63. public void setZone(Short zone) {
  64. this.zone = zone;
  65. }
  66. public String getNavigateUrl() {
  67. return this.navigateUrl;
  68. }
  69. public void setNavigateUrl(String navigateUrl) {
  70. this.navigateUrl = navigateUrl;
  71. }
  72. public Short getAreaType() {
  73. return this.areaType;
  74. }
  75. public void setAreaType(Short areaType) {
  76. this.areaType = areaType;
  77. }
  78. public Set getUsercustems() {
  79. return this.usercustems;
  80. }
  81. public void setUsercustems(Set usercustems) {
  82. this.usercustems = usercustems;
  83. }
  84. }
TbArea.java
package com.zn.entity;

import java.util.HashSet;
import java.util.Set;

/**
 * TbArea entity.
 * 
 * @author MyEclipse Persistence Tools
 */

public class TbArea implements java.io.Serializable {

	// Fields

	private String areaCode;
	private String areaName;
	private String parentAreaCode;
	private String root;
	private Short zone;
	private String navigateUrl;
	private Short areaType;
	private Set usercustems = new HashSet(0);

	// Constructors

	/** default constructor */
	public TbArea() {
	}

	/** full constructor */
	public TbArea(String areaName, String parentAreaCode, String root,
			Short zone, String navigateUrl, Short areaType, Set usercustems) {
		this.areaName = areaName;
		this.parentAreaCode = parentAreaCode;
		this.root = root;
		this.zone = zone;
		this.navigateUrl = navigateUrl;
		this.areaType = areaType;
		this.usercustems = usercustems;
	}

	// Property accessors

	public String getAreaCode() {
		return this.areaCode;
	}

	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}

	public String getAreaName() {
		return this.areaName;
	}

	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}

	public String getParentAreaCode() {
		return this.parentAreaCode;
	}

	public void setParentAreaCode(String parentAreaCode) {
		this.parentAreaCode = parentAreaCode;
	}

	public String getRoot() {
		return this.root;
	}

	public void setRoot(String root) {
		this.root = root;
	}

	public Short getZone() {
		return this.zone;
	}

	public void setZone(Short zone) {
		this.zone = zone;
	}

	public String getNavigateUrl() {
		return this.navigateUrl;
	}

	public void setNavigateUrl(String navigateUrl) {
		this.navigateUrl = navigateUrl;
	}

	public Short getAreaType() {
		return this.areaType;
	}

	public void setAreaType(Short areaType) {
		this.areaType = areaType;
	}

	public Set getUsercustems() {
		return this.usercustems;
	}

	public void setUsercustems(Set usercustems) {
		this.usercustems = usercustems;
	}

}

TbArea.hbm.xml TbAreaDAO.java 就不贴出来数据访问是用的remoting-config.xml来控制的.

Html代码 复制代码 收藏代码
  1. <destination id="Service">
  2. <properties>
  3. <source>com.zn.service.BaseService</source>
  4. </properties>
  5. </destination>
<destination id="Service">
		<properties>
			<source>com.zn.service.BaseService</source>
		</properties>
	</destination>

 

Java代码 复制代码 收藏代码
  1. public class BaseService {
  2. /**
  3. * @param wqb
  4. */
  5. public BaseService(){}
  6. public String hello(){
  7. System.out.println("---------hello-----------------");
  8. return "hehe";
  9. }
  10. @SuppressWarnings("unchecked")
  11. public List<TbArea> getArea(String areaCode){
  12. TbAreaDAO ta=new TbAreaDAO();
  13. List<TbArea> arealist=new ArrayList<TbArea>();
  14. if(areaCode==null){
  15. arealist=ta.findByAreaType(1);
  16. }else{
  17. arealist=ta.findByParentAreaCode(areaCode);
  18. }
  19. return arealist;
  20. }
  21. }
public class BaseService {

	/**
	 * @param wqb
	 */
	public BaseService(){}
	
	public String hello(){
		System.out.println("---------hello-----------------");
		return "hehe";
	}

	@SuppressWarnings("unchecked")
	public List<TbArea> getArea(String areaCode){
		TbAreaDAO ta=new TbAreaDAO();
		List<TbArea> arealist=new ArrayList<TbArea>();
		if(areaCode==null){
			arealist=ta.findByAreaType(1);
		}else{
			arealist=ta.findByParentAreaCode(areaCode);
		}
		return arealist;
	}
}

再就到FLEX的页面了:

Xml代码 复制代码 收藏代码
  1. <mx:Script>
  2. <![CDATA[
  3. import mx.rpc.events.FaultEvent;
  4. import mx.validators.ValidationResult;
  5. import mx.rpc.events.ResultEvent;
  6. import mx.collections.ArrayCollection;
  7. [Bindable]
  8. var chageArea:int=0;
  9. function init():void{
  10. service.getArea(null);
  11. }
  12. function getAreaResult(event:ResultEvent):void{
  13. if(chageArea==0){
  14. area1.dataProvider=event.result;
  15. }else if(chageArea==1){
  16. area2.dataProvider=event.result;
  17. }else{area3.dataProvider=event.result;}
  18. }
  19. function getAreaFault(event:FaultEvent):void{
  20. }
  21. function chageArea1():void{
  22. chageArea=1;
  23. area3=null;
  24. service.getArea(area1.selectedItem.areaCode);
  25. }
  26. function chageArea2():void{
  27. chageArea=2;
  28. service.getArea(area2.selectedItem.areaCode);
  29. }
  30. ]]>
  31. </mx:Script>
  32. <mx:RemoteObject id="service" destination="Service">
  33. <mx:method name="getArea" result="getAreaResult(event)" fault="getAreaFault(event)"/>
  34. </mx:RemoteObject>
  35. <mx:FormItem label="地区:" width="100%" fontSize="12">
  36. <mx:HBox width="100%">
  37. <mx:ComboBox fontSize="12" id="area1" width="75" labelField="areaName" change="chageArea1()"></mx:ComboBox>
  38. <mx:Label text="省" textAlign="center" width="20" height="100%" fontSize="14"/>
  39. <mx:ComboBox width="80" fontSize="12" id="area2" labelField="areaName" change="chageArea2()"></mx:ComboBox>
  40. <mx:Label text="市" width="20"/>
  41. <mx:ComboBox width="120" id="area3" labelField="areaName"></mx:ComboBox>
  42. </mx:HBox>
  43. </mx:FormItem>
<mx:Script>
		<![CDATA[
			import mx.rpc.events.FaultEvent;
			import mx.validators.ValidationResult;
			import mx.rpc.events.ResultEvent;
			import mx.collections.ArrayCollection;
			[Bindable]
			var chageArea:int=0;
			function init():void{
			service.getArea(null);
			}
			function getAreaResult(event:ResultEvent):void{
				if(chageArea==0){
					area1.dataProvider=event.result;
				}else if(chageArea==1){
					area2.dataProvider=event.result;
				}else{area3.dataProvider=event.result;}
			}
			function getAreaFault(event:FaultEvent):void{
			
			}
			function chageArea1():void{
				chageArea=1;
				area3=null;
				service.getArea(area1.selectedItem.areaCode);
			}
			function chageArea2():void{
				chageArea=2;
				service.getArea(area2.selectedItem.areaCode);
			}
			
		]]>
	</mx:Script>
	
	
	<mx:RemoteObject id="service" destination="Service">
		<mx:method name="getArea" result="getAreaResult(event)" fault="getAreaFault(event)"/>
	</mx:RemoteObject>

<mx:FormItem label="地区:" width="100%" fontSize="12">
<mx:HBox width="100%">
<mx:ComboBox fontSize="12" id="area1" width="75" labelField="areaName" change="chageArea1()"></mx:ComboBox>
<mx:Label text="省" textAlign="center" width="20" height="100%" fontSize="14"/>
<mx:ComboBox width="80" fontSize="12" id="area2" labelField="areaName" change="chageArea2()"></mx:ComboBox>
<mx:Label text="市" width="20"/>
<mx:ComboBox width="120" id="area3" labelField="areaName"></mx:ComboBox>
</mx:HBox>
</mx:FormItem>

 

基本上重要实现代码都有了,先留在这也许下次用得上,呵呵!

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics