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