lizongbo 的编程学习

编程学习 java为主的web应用开发

  DonewsBlog  |  Donews首页  |  Donews社区  |  Donews邮箱  |  我的首页  |  联系作者  |  聚合   |  登录
  75篇文章 :: 0篇收藏:: 35篇评论:: 2个Trackbacks

公告

lizongbo的blog


文章

收藏

相册

常用网址

存档


正在读取评论……


2005年11月


                   1. 先写一个存放选项的bean:

package com.lizongbo.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 listAllUserHtmlSelect() {
        List l = listAllUser();
        List rs = new java.util.ArrayList();
        for (int i = 0; i < l.size(); i++) {
            User u = (User) l.get(i);
            HtmlSelectStruct hsall = new HtmlSelectStruct(u.getid()+" / "+u.getName(),
                    String.valueOf(u.getid()));
            rs.add(hsall);
        }
        return rs;

    }

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

        request.getSession().setAttribute("userHtmlSelect",
                                          srl.listAllUserHtmlSelect());
//如果是null的,页面上会报错,这点不太爽

4.网页上的使用

     <html:select property="userid">

<html:option value="">不选择用户</html:option>
     <html:options collection="userHtmlSelect" property="value" labelProperty="label"/>
      </html:select>





    摘要:配置jb2006一些重要参数.    (全文共2361字)——点击此处阅读全文