Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!