package de.juplo.demo;
+import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
@RequestMapping("/")
public String display(@ModelAttribute Form form)
{
- log.info("option={}, inner={}", form.option, form.inner.option);
+ log.info(
+ "option={}, inner={}{}",
+ form.option,
+ form.inner.option,
+ form.map
+ .entrySet()
+ .stream()
+ .map(entry -> entry.getKey() + "=" + entry.getValue())
+ .collect(Collectors.joining(", ", ", ", "")));
return "form";
}
}
package de.juplo.demo;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import lombok.Data;
{
Boolean option;
Inner inner = new Inner();
+ Map<String, Boolean> map =
+ Stream.of( "foo", "bar" ).collect(Collectors.toMap(a -> a, a -> false));
}
@Data
<input type="checkbox" class="form-check-label" th:field="*{inner.option}" />
<label class="form-check-label" th:for="${#ids.prev('inner.option')}">Another Option (In An Inner Class)</label>
</div>
+ <div class="form-group" th:each="key : *{map.keySet()}">
+ <input type="checkbox" class="form-check-label" th:field="*{map[__${key}__]}" />
+ <!-- <label class="form-check-label" th:for="${#ids.prev('map[__${key}__]')}" th:text='|Option "${key}" From The Map|'>Option "KEY" From The Map</label>-->
+ <label class="form-check-label" th:text='|Option "${key}" From The Map|'>Option "KEY" From The Map</label>
+ </div>
</div>
</div>
<div class="card-footer">