站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题关于struts的下拉框问题,急!!!!!!

关于struts的下拉框问题,急!!!!!!

摘要: 关于struts的下拉框问题,急!!!!!!


ActionForm中有这样的代码
public Collection optionCollection = new ArrayList();
public void setOptionCollection(){
Vector options = new Vector();
options.add(new SetHTMLOption("请选择","请选择"));
options.add(new SetHTMLOption("sdfsdfdsf","sdfsadfdsf"));
......
......
this.optionCollection.add(options);
}
public Collection getOptionCollection(){return this.optionCollection;}

在reset中这样写的
this.setOptionCollection();
request.setAttribute("optionCollection",this.getOptionCollection());

在JSP页面中是这样写的




这个是一个类 SetHTMLOption
private String optionValue;
private String optionName;

public SetHTMLOption() {}

public SetHTMLOption(String value,String name){
this.optionValue = value;
this.optionName = name;
}

public void setOptionValue(String value){
this.optionValue = value;
}
public String getOptionValue(){return this.optionValue;}

public void setOptionName(String name){
this.optionName = name;
}
public String getOptionName(){return this.optionName;}

当运行时提示下面的错误
No getter method available for property optionName for bean under name [cn.com.sharey.struts.forms.SetHTMLOption@c38157, cn.com.sharey.struts.forms.SetHTMLOption@1609c13, cn.com.sharey.struts.forms.SetHTMLOption@1a6b16f, cn.com.sharey.struts.forms.SetHTMLOption@cb2185, cn.com.sharey.struts.forms.SetHTMLOption@5ce40, cn.com.sharey.struts.forms.SetHTMLOption@127ff0d, cn.com.sharey.struts.forms.SetHTMLOption@d9cbcb, cn.com.sharey.struts.forms.SetHTMLOption@d2b64e, cn.com.sharey.struts.forms.SetHTMLOption@1bef1ac, cn.com.sharey.struts.forms.SetHTMLOption@ec6bb1, cn.com.sharey.struts.forms.SetHTMLOption@192425a]


不知道为什么,请各位帮助!!!!


哪位知道怎么解决或者讲讲怎么使用struts的下拉框!!!!!


没人知道吗?哪大家都怎么做下拉框啊??


public Collection optionCollection = new ArrayList();
可能不行
这样写可以
private SetHtmlOption aaa[];

a[1].xx,a[1].y=......
public SetHtmlOption getOptionCollection {return aaa;}


从你的代码看,好像的确没什么地方写错了。
你再去看看Struts中option的用法吧
你在SetHTMLOption类里是用的getOptionName()方法获取的optionName的值,确在页面用
label="optionName" 这样直接获得optionName的值,我感觉这里有点行不通
你考虑下,这个get方法Struts有没有帮你调用
我以前也用Struts做过项目,好像我就是用的html语言的普通<select><option>...</select>
哦,你是应该看Struts里关于Select的用法,我就只能给你这些建议了。


试过了,不行,不是提示同样的错误


不会吧,我现成的代码就这样做的
public SetHtmlOption getOptionCollection {return aaa;}
这句修改成
public SetHtmlOption[] getOptionCollection {return aaa;}


a[1].xx,a[1].y=......
这个提示空指针


STRUTS下拉框倒底怎么用啊??????


struts 的下拉框和普通的下拉框没什么不一样,只是多了个html做标签


哪里有这样写的撒??
你在HTML中写的是:property="optionCollection" ,而这玩意是什么?
是this.optionCollection.add(options)!
也就是optionCollection里面不是一个一个的SetHTMLOption,而是一整个Vector
当然取不到值了.
你把
this.optionCollection.add(options);
改成
this.optionCollection=options;
再试



谢谢,问题解决了

现在明白了,其实真接用Collection就行了,返回Collection,而不必用Vector

public Collection optionCollection = new ArrayList();
optionCollection.add(.....);

retrun optionCollection;

这样就可以了


↑返回目录
前一篇: 两段几乎相同的JSP页面,一个怎么也不能去处表格(table)线,一个却没有表格线,晕了,彻底晕了
后一篇: 七嘴八舌:JSP中使用存储过程的问题。。。。。。