struts标签学习-logic and bean:write

struts标签学习

logic:iterate 循环列出collection数组接口的所有值,

bean;write 相当于Response.GetAttribute("xxxx");

需要注意的是其可以取出list数组中对象的属性,如下所示。

 <select name="newsclass" onChange="javascript:ChangeMenu(this.value);">
           <option value="0">全部类别</option>
           <logic:iterate name="ClassList" property="list" id="list">
           <option value="<bean:write name="list" property="param0"/>" <bean:write name="list" property="param2"/>><bean:write name="list" property="param1"/></option>
           </logic:iterate>
       </select>

 

——————————————————————————

/*
 * 创建日期 2005-8-27
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
package org.infosys.logic;

import java.util.ArrayList;
import java.util.List;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;

import com.infosys.Hibernate.SessionFactory;
import com.infosys.Hibernate.TblNewsclass;

/**
 * @author Administrator
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class ClassList {
 private List list=new ArrayList();
 /**
  * 有默认选项的构造器
  * @param selGroup
  */
 public ClassList(){
  List group=new ArrayList();
    Session session;
    try {
   session = SessionFactory.currentSession();
   group=session.find("from TblNewsclass t order by t.vieworder asc");
  } catch (HibernateException e) {
   e.printStackTrace();
  } finally {
   try {
    SessionFactory.closeSession();
   } catch (HibernateException e1) {
    e1.printStackTrace();
   }
  }
  list=new ArrayList();
  TblNewsclass newsClass;
  ComParam param;
  for(int i=0;i<group.size();i++){
   newsClass=(TblNewsclass)group.get(i);
   param=new ComParam();
   param.setParam0(newsClass.getClasscode());
   param.setParam1(newsClass.getClassname());
   list.add(param);
  }
 }
 /**
  * 有默认选项的构造器
  * @param selGroup
  */
 public ClassList(String selClass){
  List group=new ArrayList();
    Session session;
    try {
   session = SessionFactory.currentSession();
   group=session.find("from TblNewsclass t order by t.vieworder asc");
  } catch (HibernateException e) {
   e.printStackTrace();
  } finally {
   try {
    SessionFactory.closeSession();
   } catch (HibernateException e1) {
    e1.printStackTrace();
   }
  }
  String selStatus="";
  list=new ArrayList();
  TblNewsclass newsClass;
  ComParam param;
  for(int i=0;i<group.size();i++){
   newsClass=(TblNewsclass)group.get(i);
   param=new ComParam();
   param.setParam0(newsClass.getClasscode());
   param.setParam1(newsClass.getClassname());
   if(newsClass.getClasscode().equals(selClass)){
    selStatus="selected";
   }else{
    selStatus="";
   }
   param.setParam2(selStatus);
   list.add(param);
  }
 }
 
 /**
  * 有默认选项的构造器
  * @param selClass //选择的类别
  * @param selFlag //选择的标识
  */
 public ClassList(String selClass,String selFlag){
  List group=new ArrayList();
    Session session;
    try {
   session = SessionFactory.currentSession();
   group=session.find("from TblNewsclass t order by t.vieworder asc");
  } catch (HibernateException e) {
   e.printStackTrace();
  } finally {
   try {
    SessionFactory.closeSession();
   } catch (HibernateException e1) {
    e1.printStackTrace();
   }
  }
  String selStatus="";
  list=new ArrayList();
  TblNewsclass newsClass;
  ComParam param;
  for(int i=0;i<group.size();i++){
   newsClass=(TblNewsclass)group.get(i);
   param=new ComParam();
   param.setParam0(newsClass.getClasscode());
   param.setParam1(newsClass.getClassname());
   if(selClass.indexOf(","+newsClass.getClasscode()+",")>=0){
    selStatus=selFlag;
   }else{
    selStatus="";
   }
   param.setParam2(selStatus);
   list.add(param);
  }
 } 
 /**
  * @return 返回 list。
  */
 public List getList() {
  return list;
 }
 /**
  * @param list 要设置的 list。
  */
 public void setList(List list) {
  this.list = list;
 }
}
————————————————————————————————————————

 

你可能感兴趣的:(JavaScript,bean,Hibernate,.net,struts)