Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
Automatic set value on dropdown JSP

I'm having trouble getting auto value from DB and making auto value checked in the page edit page

here the JSP

                <c:if test="${l.code == 'USER_NOT_BLOCK'  }">
                    <td> 
                        <select class="selectpicker" id="value-${l.code}" name="value-${l.code}" multiple="multiple">
                            <c:forEach items="${listUser}" var="list">
                                <option value="${list}" >${list}</option>
                            </c:forEach>
                        </select>
                    </td>
                </c:if>

and this one the controller

public ModelAndView addPref(@RequestParam String code) throws Exception{
    ModelAndView mv=null;
    List<SystemParameter> list = null;
    String listUser = "";
    
    
    try {
        mv = new ModelAndView("page.pref.add");
        
        list = this.sysParamService.getPreferenceDetail(code);
        listUser = this.userService.getUsername();
        System.out.println(listUser.toString());
        mv.addObject("list", list);
        mv.addObject("listUser", listUser); //this is the dropdown value
        mv.addObject("code", code);
    }
    catch(Exception e){
        LOG.error("Exception at addPref()", e);
    }
    finally{
        list = null;
    }

I am open to all your suggestions, even using javascript is not a problem

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The generic pattern to select a value in a list with JSP is

<c:set var="list" value="${fn:split('ONE,TWO,THREE,FOUR', ',')}"/>
<c:set var="selectedItem" value="TWO"/>

<select>
   <c:forEach items="${list}" var="item">
      <option value="${item}" ${item == selectedItem ? 'selected':''}>${item}</option>
   </c:forEach>
</select>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda