Thymeleaf th: pre-procesamiento de campo no está trabajando con th: cada uno

Rahul Raj:

Quiero mostrar una lista de objetos en una mesa junto con la opción de actualizar uno de los campos marketallcoationen vivo. Y uso thymeleaf para el propósito. Por lo tanto, tuve que usar th:eachen combinación con la capacidad de pre-procesamiento in disponible th:field.

En mi clase del controlador, que establece el atributo como se muestra a continuación:

model.addAttribute("marketList",supplyAllocationService.getItems());

Y en mi página HTML, hago algo como esto:

<table>
<tr th:each="market,iteration : *{marketList}">
                <td><span th:text="${market.date}" th:field="*{marketList[__${iteration.index}__].date}"> Date </span></td>
                <td><span th:text="${market.country}" th:field="*{marketList[__${iteration.index}__].country}"> Country </span></td>
                <td><span th:text="${market.product}" th:field="*{marketList[__${iteration.index}__].product}"> Product </span></td>
                <td><span th:text="${market.sku != null} ? ${market.sku} : 'None'" th:field="*{marketList[__${iteration.index}__].sku}"> SKU </span></td>
                <td><span th:text="${market.aggregateddemand}" th:field="*{marketList[__${iteration.index}__].aggregateddemand}"> Aggregated Demand </span></td>
                <td><span th:text="${market.aggsupply_12}" th:field="*{marketList[__${iteration.index}__].aggsupply_12}"> 12 weeks aggregated supply </span></td>
                <td><input type="text" th:value="${market.marketallcoation}" th:field="*{marketList[__${iteration.index}__].marketallcoation}"/></td>
                <td><span th:text="${market.unmetdemand}"  th:field="*{marketList[__${iteration.index}__].unmetdemand}"> Unmet demand quantity </span></td>
                <td><span th:text="${market.demandplanner}" th:field="*{marketList[__${iteration.index}__].demandplanner}"> Demand Planner </span></td>
                <td><span th:text="${market.bdmcontact}" th:field="*{marketList[__${iteration.index}__].bdmcontact}"> BDM contact </span></td>
                <td></td>
            </tr>
</table>

Cuando ejecuto el código, me sale el siguiente error:

Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'marketList[0]' available as request attribute
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153) ~[spring-webmvc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903) ~[spring-webmvc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]

Según los documentos , sin necesidad de th:objectse utiliza si la funcionalidad de pre-procesamiento. No he utilizado de modo. No estoy seguro de lo que me estoy perdiendo aquí. Altamente apreciar si alguien me puede sugerir en este. He intentado un montón de puestos existentes aquí en stackoverflow, pero sin suerte hasta ahora.

Metroid:
  1. Si está utilizando *{...}la sintaxis y / o el th:fieldatributo, entonces usted tiene que utilizar un th:object(ambos dependen del th:objecta función).
  2. No se debe utilizar th:fielden un <span/>elemento - que no tiene sentido. ( th:fieldJuegos de la name, id, y valueatributos de un elemento. nameY valueno afectan <span />s.)

También, por desgracia, no creo que se puede utilizar una Listcomo un objeto de formulario. Así que para fijar su forma, es necesario crear primero un nuevo objeto que tiene marketListcomo una de sus propiedades, a continuación, añadir que el modelo en su lugar. Hacer que el nuevo objeto th:objectde su formulario, entonces el procesamiento previo debe trabajar para usted.

<form th:object="${yourNewObject}>
  <table>
    <tr th:each="market, iteration: *{marketList}">
      <td th:text="${market.date}" />
      <td th:text="${market.country}" />
      <td th:text="${market.product}" />
      <td th:text="${market.sku != null} ? ${market.sku} : 'None'" />
      <td th:text="${market.aggregateddemand}" />
      <td th:text="${market.aggsupply_12}" />
      <td><input type="text" th:field="*{marketList[__${iteration.index}__].marketallcoation}"/></td>
      <td th:text="${market.unmetdemand}" />
      <td th:text="${market.demandplanner}" />
      <td th:text="${market.bdmcontact}" />
      <td></td>
    </tr>
  </table>
</form>

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=297014&siteId=1
Recomendado
Clasificación