4
Observe the code well in my controller;
@RequestMapping("/produtos/form")
public ModelAndView form() {
ModelAndView modelAndView = new ModelAndView("produtos/form");
modelAndView.addObject("tipos", TipoPreco.values());
return modelAndView;
}
this is my html page, and write the following annotation at the top of the page
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
with the above annotation it is possible to take the list as follows;
<c:forEach items="${tipos}" var="tipoPreco" varStatus="status">
<div>
<label>${tipoPreco}</label>
<input type="text" name="precos[${status.index}].valor">
<input type="hidden" name="precos[${status.index}].tipoPreco" value="${tipoPreco}">
</div>
</c:forEach>
There is nothing wrong with everything described now, I just wanted to know how it would look in Thymeleaf, the only thing that would change would be the html part, I just need to modify the html part.
=======================================================================
That was my attempt
<select>
<table>
<tr th:each="tipo : ${status}">
<td></input type="text" name="precos[${status.index}].valor"></td>
<td></input type="text" name="precos[${status.index}].tipo"></td>
</tr>
</table>
</select>
and is generating this error
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Apr 05 06:43:15 BRT 2016
There was an unexpected error (type=Internal Server Error, status=500).
Exception parsing document: template="produtos/form", line 31 - column 8
===================================================================
Consoles
org.xml.sax.SAXParseException: O tipo de elemento tr" deve ser encerrado pela tag final correspondente "</tr>".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source) ~[na:1.8.0_65]
//////////////////////////////////////////////////////////////////////////
I tried this way;
<select>
<table>
<tr th:each="tipo : ${status}">
<td><input type="text" name="precos[${status.index}].valor"></td>
<td><input type="text" name="precos[${status.index}].tipo"></td>
</tr>
</table>
</select>
and made that mistake;
org.xml.sax.SAXParseException: O tipo de elemento input" deve ser encerrado pela tag final correspondente "</input>".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[na:1.8.0_65]
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) ~[na:1.8.0_65]
I made my attempts, they didn’t need to put them as -1
– wladyband
+1 for the effort to ask the question with much information.
– durtto