1

As I say int the title I loose information in the object that comes back from JSP to Controller.

From my Controller I pass a ModelAndView with an object of class Historic. In the JSP page I have access to all of the values of this object, but when I submit I just get part of this information, some looses on the way on.

Controller:

@GetMapping("/tt")
public ModelAndView index(Model model) {
HistoricBO historic = new HistoricBO();
// ... I fulfill this object ...
return new ModelAndView("tt", "historic", historic);
}

In JSP I have access to all the information that I passed. I use the values in two different ways. The first one (information that later I won't be able to recover) is:

<form:form method="POST" action="/addInput" modelAttribute="historic">
....
<form:label path="userHistoric[0].user.name" />
<form:input path="userHistoric[0].user.name" disabled="true" />

Being userHistoric a list inside HistoricBO object.

And the other way that I use the object values is daoing loop to the registers and show them. I can have these values after submit:

c:forEach items="${historic.userHistoric[0].periods[0].registers}" var="reg" varStatus="rog">
...
<td class="tab-odd">
  <form:input path="userHistoric[0].periods[0].registers[${rog.index}].hours[0]" class="monin" type="number" />
</td>

The method that catch the submit is as follows:

@PostMapping("/addInput")
public String savePeriod(
        @ModelAttribute("historic") HistoricBO inputs,
        BindingResult result, ModelMap model) {
    if (result.hasErrors()) {
        return "error";
    }
...

And here the object inputs only has setted the hours values, the rest of the object is empty.

Can you please why is the info loosing and how to solve it? Thanks

Mikev
  • 2,012
  • 1
  • 15
  • 27
trivili
  • 15
  • 6

1 Answers1

0

Remove disabled="true" and use readonly="true" or readonly="readonly" instead like below.

<form:input path="userHistoric[0].user.name" readonly="readonly" />

Disabled values will not be submitted with the form.

See this values-of-disabled-inputs-will-not-be-submitted and demo here.

Alien
  • 15,141
  • 6
  • 37
  • 57
  • Thanks so much. One problem solved! But I still have other doubt: if I send an object with String and Int parameters and I only display de String one, how can I do to don't lose the Int without have to show it in the form? – trivili Mar 13 '19 at 12:28
  • send parameters in hidden if you dont want to show in form. if it doesnt serve your purpose then feel free to post new question and paste the link here ..i would be happy to help you.please consider accepting and upvoting the answer. – Alien Mar 13 '19 at 12:30