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) |