点集贵州电脑网
 
 
 梦想之源 ›› 灌水专区 ›› itemselection的问题 版主:
灌水专区
新建论坛
申请免费TS
1 / 1 页
<< 1 >>
跳转
 主题:itemselection的问题
 
 lele
发表时间:[2008-04-11 09:53:59] [向作者发站内短信] [复制链接告诉朋友]
等 级:列兵
经 验:498
性 别:帅哥
文 章:138
精 华:0

 1.  page

   <component id="rclist" type="PropertySelection">
          <binding name="model" value="ognl:getSelect('1100006','action=getrunningcyclelist','com.longcredit.KEye.app.business.PO.Device','getName','getId')"/>
          <binding name="value" value="ognl:po.rcid"/>
    </component>

 2.页面

             <td align="left" colspan="3">
              <select name="rclist_select" id="rclist"
               jwcid="rclist" style="width:170px">

              </select>
             </td>

3. ItemsSelection.java

 

public class ItemsSelection implements IPropertySelectionModel, Serializable{
 
   private List itemList=new ArrayList();

   private String  clspath;
  
   private String method_label_name;
  
   private String method_value_name;
  
   private Object obj;
  
   public Method method_lable;
  
   public Method method_value;
  
   String label_value;
  
   String value;
  
   public ItemsSelection(){
   
   
   }
   public ItemsSelection(List itemList,String clspath,
              String method_label_name,String method_value_name) {
   
       this.itemList = itemList;
      
       this.clspath = clspath;
      
       this.method_label_name = method_label_name;
      
       this.method_value_name = method_value_name;
      
       try {
   this.obj = AppHelper.newInstance(this.clspath);
   
  } catch (Exception e) {
  
   e.printStackTrace();
  }
      
  try {
   this.method_lable = obj.getClass().getMethod(this.method_label_name, new   Class[] {});
  } catch (SecurityException e) {
   
   e.printStackTrace();
  } catch (NoSuchMethodException e) {
  
   e.printStackTrace();
  }
      
  try {
   this.method_value = obj.getClass().getMethod(this.method_value_name, new   Class[] {});
  } catch (SecurityException e) {
   
   e.printStackTrace();
  } catch (NoSuchMethodException e) {
  
   e.printStackTrace();
  }
   }

   public int getOptionCount() {
    return itemList.size();
   }

   public Object getOption(int index) {
       return itemList.get(index);
   }

   public String getLabel(int index) {
  
  obj = itemList.get(index);
  
  
  try {
   label_value = ((String ) this.method_lable.invoke(obj, new Object[] {})).toString();
  } catch (IllegalArgumentException e) {
  
   e.printStackTrace();
  } catch (IllegalAccessException e) {
  
   e.printStackTrace();
  } catch (InvocationTargetException e) {
 
   e.printStackTrace();
  }
       return   label_value;
   }

   public String getValue(int index) {
   
   obj = itemList.get(index);
   
     
   try {
    value = ((String ) this.method_value.invoke(obj, new Object[] {})).toString();
   } catch (IllegalArgumentException e) {
   
    e.printStackTrace();
   } catch (IllegalAccessException e) {
   
    e.printStackTrace();
   } catch (InvocationTargetException e) {
  
    e.printStackTrace();
   }
        return   value;
   
      
   }
   public Object translateValue(String value) {
   
    int index=0;
    String s = "";
    for(int i=0;i<itemList.size();i++){
    
     obj = itemList.get(i);
    
     try {
     
    s = this.method_value.invoke(obj, new Object[] {}).toString();
    
   } catch (IllegalArgumentException e) {
 
    e.printStackTrace();
   } catch (IllegalAccessException e) {
 
    e.printStackTrace();
   } catch (InvocationTargetException e) {
 
    e.printStackTrace();
   }
     if(value.equals(s))
     {
      index=i;
     }    
    }
       return getOption(index);
   }
 
 
 

}

4.问题:

之前没有使用反射原理对应的PO时,是正常的

之前的使用方式如下:

public class ItemSelection implements IPropertySelectionModel, Serializable{
 
   private List itemList=new ArrayList();

   public ItemSelection(List itemList) {
       this.itemList = itemList;
   }

   public int getOptionCount() {
    return itemList.size();
   }

   public Object getOption(int index) {
       return itemList.get(index);
   }

   public String getLabel(int index) {
       return ((Attribute) itemList.get(index)).getValue();
   }

   public String getValue(int index) {
          return ((Attribute) itemList.get(index)).getKey();
  
   }
   public Object translateValue(String value) {
   
    int index=0;
    for(int i=0;i<itemList.size();i++){
     Attribute po=(Attribute)itemList.get(i);
     if(value.equals(po.getKey()))
     {
      index=i;
     }    
    }
       return getOption(index);
   }
 
 
 

}

改了后出现的问题:

提交之后,对应的po.rcid值是

rcid=com.longcredit.KEye.app.business.PO.Device

应该是478才对

请分析下出错的可能.

页面类里的传入参数都是正确的,没问题(List itemList,String clspath,
              String method_label_name,String method_value_name
)


 楼主更多新贴 :  
灌水专区jfreechart图形上的链接
灌水专区itemselection的问题
灌水专区ognl:devicegroup.id
灌水专区foreach的问题
  楼1  
等 级:下士
经 验:1683
性 别:帅哥
文 章:496
精 华:2
 干煸四季豆
发表时间:[2008-04-12 13:45:13] [向作者发站内短信] [复制链接告诉朋友]

没怎么看懂,好复杂。

<binding name="model" value="ognl:getSelect('1100006','action=getrunningcyclelist','com.longcredit.KEye.app.business.PO.Device','getName','getId')"/>

这样的写法,汗一下,我不清楚你应用反射为什么,但是另外一种写法,或许会更方便写。

 <component id="rclist" type="PropertySelection">
          <binding name="model" value="itemsSelection"/>
          <binding name="value" value="ognl:po.rcid"/>
    </component>

public IPropertySelectionModel getItemsSelection() {

         return new ItemsSelection(.................................)

}

关于发射,你可以设断点看看每一行运行的值是否正确。

不过我觉得你这样的做法,估计性能不咋地,PropertySelection无非就是要一个集合,你可以在我上面写的getItemsSelection() 方法里面,先构造好集合,在实现PropertySelection,估计写起来会简单些,性能也好些。

1 / 1 页
<< 1 >>
跳转
  快速回复
  帐号: 密码: 匿名不登陆
回复内容:  
验 证 码:
 
 
·VIP收费TS,您明智的选择!
·9800GT+19'液晶DIY仅售3500元
·双核特惠:1999、2999、3999
·什么是点金积分,如何查看自
·团购一期:三星R458-DS0G+高
  
贵州点集科技发展有限责任公司·点集贵州电脑网 版权所有©2006-2008
中华人民共和国增值电信业务经营许可证 黔B-20070010号
客服QQ: 93804809818866281927205370
电子邮件: deangi@vip.sina.com
技术支持: 0851-5109268