Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda