java后台为前台JSP页面的SELECT标签设置值

    技术2022-05-18  14

    后台写法:List<LabelValueBean> roleList = new ArrayList<LabelValueBean>();   request.setAttribute("roleList", roleList);   dto = ctlBL.getUserRolesNotInProcess(dto);   List<UserRoleInfo> list = dto.getUserRoleList();   for(UserRoleInfo info : list){    //前面的是页面显示的值,后面的是要存储的值    roleList.add(new LabelValueBean(info.getRolename(), info.getRoleid().toString()));   }   if(roleList.isEmpty()){    roleList.add(new LabelValueBean("", ""));   }页面写法:<html:select  property="prroleid" style="width: 120px;"  errorStyleClass="inputError imeActive" tabindex="2"  οnchange="changePrRolename()">  <html:options collection="roleList" property="value" name=""   labelProperty="label"/> </html:select>

     

    原理就是在后台做一个LabelValueBean的list,发到前台的option处,通过标签自动进行值的处理~~~


    最新回复(0)