Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Architecture & Framework » Struts  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 使用STRUTS构架,从数据库里读取内容放到下拉框
keliu123





发贴: 2
积分: 0
于 2005-11-16 10:49 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
能否给个实例,参考参考


作者 Re:使用STRUTS构架,从数据库里读取内容放到下拉框 [Re:keliu123]
linux_china



版主


发贴: 752
积分: 240
于 2005-11-16 11:34 user profilesend a private message to usersend email to linux_chinasearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
创建一个新的类,继承OptionsTag,然后加入从数据库中读取数据代码即可,非常简单。 我有时就这么做。


作者 Re:使用STRUTS构架,从数据库里读取内容放到下拉框 [Re:linux_china]
keliu123





发贴: 2
积分: 0
于 2005-11-16 12:45 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
可不可以给个例子,让我看看.你这样说我感觉很迷糊


作者 Re:使用STRUTS构架,从数据库里读取内容放到下拉框 [Re:linux_china]
bluepure

pureblue



发贴: 509
积分: 85
于 2005-11-16 17:06 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1. 先写一个

package com.bluepure.common.basic;

public class HtmlSelectStruct {

private String label;
private String value;
public HtmlSelectStruct() {
}

public HtmlSelectStruct(String label, String value) {
this.setLabel(label);
this.setValue(value);
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}

2.生成下拉列表:
例如
public List listAllUserTypeHtmlSelect() {
List l = listAllUserType();
List rs = new java.util.ArrayList();
for (int i = 0; i < l.size(); i++) {
UserType u = (UserType) l.getLight Bulb;
HtmlSelectStruct hsall = new HtmlSelectStruct(u.getFtypeid()+" / "+u.getFname(),
String.valueOf(u.getFtypeid()));
rs.add(hsall);
}
return rs;

}

3.放到session中,放到request里也可以

request.getSession().setAttribute("userinfoHtmlSelect",
srl.listAllTopUserTypeHtmlSelect());
//如果是null的,好像页面上会报错的

4.网页上的使用

<html:select property="userid">
<html:options collection="userinfoHtmlSelect" property="value" labelProperty="label"/>
</html:select>

搞定.



作者 Re:使用STRUTS构架,从数据库里读取内容放到下拉框 [Re:keliu123]
wmgreat



CJSDN高级会员


发贴: 286
积分: 105
于 2005-11-16 18:40 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
LableValueBean就可以搞定了吧


新世纪的曙光点亮了我们略带近视的眼睛。我们终于明白,诸神早已迎来了他们的黄昏,旧的偶像也都已纷纷落地,新的偶像还在摇篮里嗷嗷待哺……

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923