posts - 495,comments - 227,trackbacks - 0
2006-10-31 19:55

****************************************************************************************************************

DAO里面如下写:

package com.sinoconcept.match.dao.impl;

import java.util.List;

import org.springframework.dao.DataAccessException;

import com.sinoconcept.match.dao.DirctDAO;

public class DirctDAOImpl extends BaseDAOHibernateImpl implements DirctDAO {

 public List loadAll(String className) {
  
  try {
   return this.getHibernateTemplate().loadAll(Class.forName(className));
  } catch (DataAccessException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return null;
 }

}

***************************************************************************************************************

service里如下写:

package com.sinoconcept.match.service.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.apache.struts.util.LabelValueBean;

import com.sinoconcept.match.dao.DirctDAO;
import com.sinoconcept.match.service.DirctService;

public class DirctServiceImpl implements DirctService {
 private DirctDAO dirctDAO;

 public List getDirect(String dirName) {

  List result = this.getDir(dirName);
  return result;
 }

 public List getDirectLabelValueBean(String dirName) {

  List result = this.getDirLableValueBean(dirName);
  return result;
 }

 public List getDir(String dirName) {
  List result = null;

  result = dirctDAO.loadAll(dirName);

  return result;
 }

 @SuppressWarnings("unchecked")
 public List getDirLableValueBean(String dirName) {
  List result = new LinkedList();
  List list = getDir(dirName);
  Iterator it = list.iterator();
  while (it.hasNext()) {
   Object obj = it.next();
   LabelValueBean lv = new LabelValueBean();
   String label = null;
   try {
    label = obj.getClass().getMethod("getName", new Class[] {})
      .invoke(obj, null).toString();
   } catch (Exception e) {
    try {
     label = obj.getClass()
       .getMethod("getValue", new Class[] {}).invoke(obj,
         null).toString();
    } catch (IllegalArgumentException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    } catch (SecurityException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    } catch (IllegalAccessException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    } catch (InvocationTargetException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    } catch (NoSuchMethodException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    }
   } finally {
    if (label == null)
     try {
      label = label = obj.getClass().getMethod("getValue",
        new Class[] {}).invoke(obj, null).toString();
     } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     } catch (SecurityException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     } catch (InvocationTargetException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     } catch (NoSuchMethodException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
   }
   lv.setLabel(label);
   try {
    lv.setValue(obj.getClass().getMethod("getId", new Class[] {})
      .invoke(obj, null).toString());
   } catch (IllegalArgumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (SecurityException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (InvocationTargetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (NoSuchMethodException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   result.add(lv);
  }
  return result;
 }

 public DirctDAO getDirctDAO() {
  return dirctDAO;
 }

 public void setDirctDAO(DirctDAO dirctDAO) {
  this.dirctDAO = dirctDAO;
 }

}

***********************************************************************************************************************

Action里面如下设置:

String status = request.getParameter("status");
  if (status == null || status.equals("")) {
   status = "0";
  }

List sttusList = dirctService
    .getDirectLabelValueBean("com.sinoconcept.match.domain.DrStatus");//数据字典表

//DrStatus 数据映设文件只要二个字段:private Integer id;private String value;

manDiaryForm.setStatus(status);

request.setAttribute("statusList", sttusList);

****************************************************************************************************************

页面上如下获得:

<html:select property="status" onchange="sel()">
       <html:optionsCollection name="statusList" />
      </html:select>

posted on 2006-11-16 09:44 SIMONE 阅读(672) 评论(0)  编辑  收藏 所属分类: struts

只有注册用户登录后才能发表评论。


网站导航: