0

I know there are a buch of post related with this out there but none of them have worked for me.

I dont know if what I want to do is easy or no. I am very very new working with Spring.

The aplication is already working and I have to do some modifications, so I want to fill a dropdown box with data requested from a database.

This is my view:

<form:form action="${urlcallBankAddAction}" method="POST" onsubmit="return validar(this)" modelAttribute="banco"> 
     <form:select path="descripcion" items="${resultList.descripcion}" />
</form:form>

This is my Controller:

@RequestMapping(value = {"/details", "/details?status={status}"}, method = RequestMethod.GET)
public String verBancos(WebRequest request,
        ModelMap model,
        HttpSession session){

    try{
        String valorSesion = (String) session.getAttribute("acceso");//Se valida el inicio de sesion
        if(valorSesion.equals("1")){//Se valida el inicio de sesion
            List<Banco> result = new ArrayList<Banco>();
                            List<String> banksResults = new ArrayList<String>();

            result = bancoService.obtenerTodosLosBancos();                                

            model.addAttribute("currentComponent", "banks.title");
            model.addAttribute("status", request.getParameter("status"));
            model.addAttribute("resultList", result);
                            model.addAttribute("banco", new Banco());
            model.addAttribute("cantidadRegistros", result.size());
            return "details";
        } else{
            //MANDAR A PAGINA DE ERROR
            return "redirect:/unauthorized";
        }
    } catch(NullPointerException n){//Se valida el inicio de sesion
        //MANDAR A PAGINA DE ERROR
        return "redirect:/unauthorized";
    }
}

And this is the Model, the sets and gets are there but I Omitted in here:

@Id
@Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@Column(name = "cod_visa")
private int codigoVisa;

@Column(name = "CodSud")
private String codigoSudeban;

@Column(name = "descripcion"

Something curious about all this is that I already have the data as you can see in the image below, but I only Want to display in my box the description of those clients, the arrow denotes where I want to put my description.

With the current view I got this exception:

Caused by: java.lang.NumberFormatException: For input string: "descripcion"

And I also tried filling the box with a c:forEach items="${resultList.description} with no result and I used only the "resultList" and then I got the whole object obtained from DB.

enter image description here

Please help me out with this, I dont know what I am missing or what I am doing wrong. I have faced so many problems with this.

1 Answer 1

1

if you want to display the description of every banco on your resultList use itemLabel and itemValue, take a look at Spring documentations:

  <form:select path="descripcion" items="${resultLis}" itemValue="id" itemLabel="description"/>

It can be done through the options tag as well:

 <form:select path="descripcion">
  <form:options items="${resultLis}" itemValue="id" itemLabel="description"/>
 </form:select>

using JSTL :

   <form:select path="descripcion">
    <c:forEach items="${resultList }" var="banco">
        <form:option value="${banco.id }" label="${banco.description }"/>
    </c:forEach>
   </form:select>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.