首页 > 解决方案 > 组合框中带有百里香叶的默认值

问题描述

我有百里香叶的问题。我有一个带有组合框和一些字段的表单。我想将默认值放在组合框中,并且“选择”的子句对我不起作用。

代码是这样的:

<select class="dsp-inline form-control" th:field="*{tipoDocumento}" required="required" th:disabled="${permisoXestion == false}">
      <option value="" th:text="#{select.option.default}"> </option>
      <option th:each="row : ${tipoDocumento}" th:value="${row}" th:text="#{${row.value}}" th:selected="#{${row==2}}"></option>
</select>

其中“tipoDocumento”是一个具有两个值的枚举:

public enum TipoDocumento {
 PUBLICO("documento.tipo.publico"),
 PRIVADO("documento.tipo.privado");

private String property;

private String value;

private TipoDocumento(String property) {

    this(property, null);

    }

private TipoDocumento(String value, String property) {
   this.value = value;
   this.property = property;

}

public String getValue() {
    return value;
}

public void setValue(String value) {
    this.value = value;
}

public String getProperty() {
    return property;
}

public void setProperty(String property) {
    this.property = property;
}
}

有人能帮我吗?

标签: htmlwinformscomboboxfrontendthymeleaf

解决方案


选定的标签应该可以工作。请记住,它需要像selected="selected". 我已经在几个选择中使用它并且它总是有效的。此外,th:each您需要删除该th:selected="#{${row==2}}"元素,否则您的第一个选项将不是默认选项。

<select class="dsp-inline form-control" required="required" th:disabled="${permisoXestion == false}">
      <option value="" th:text="#{select.option.default}"></option>
      <option th:each="row, iter : ${tipoDocumento}" th:value="${row}" th:text="#{${row.value}}" th:selected="${iter.count eq 2} ? 'selected' : 'false'"></option>
</select>

推荐阅读