当前位置: 首页 > 知识库问答 >
问题:

组合框中带有胸腺叶的默认值

颜鸿云
2023-03-14

我有一个问题胸腺。我有一个带有组合框和一些字段的表单。我想把默认值放在组合框中,而“选择”对我不起作用。

代码如下:

<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;
}
}

有人能帮我吗?

共有2个答案

锺离卓
2023-03-14

如果使用th:selected,则不能使用th:field。必须用名称属性替换它。那么,你能替换吗

<select class="dsp-inline form-control" th:field="*{tipoDocumento}" required="required" th:disabled="${permisoXestion == false}">

 <select class="dsp-inline form-control" name="tipoDocumento" required="required" th:disabled="${permisoXestion == false}">

另外,th的条件:选中可以替换吗

th:selected="#{${row==2}}"

th:selected="${row==2}"
姬乐池
2023-03-14

选定的标签应该可以工作。请记住,它需要像选定="选定"一样添加。我在几个选择中使用过它,它总是有效的。此外,在您的th: each中,您需要删除th: select="#{${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>
 类似资料:
  • 当图像存在时,我想在thymleaf中显示背景图像,但如果不存在,我想在那里显示默认图像。我试过的如下 在最后一个空引用中,我想放一个这样的默认图像 但它显示出错误。正确的语法是什么?

  • 我想做一些像 在百里香叶中。我知道有一个价值观,我要做的就是 如何在Thyemleaf的select选项中传递两个值。

  • 我试图在thymleaf中迭代函数列表。这就是我所做的。 控制器: 并在html中: 我是新来的。我做错了什么?或者我应该使用?

  • 我想把JavaScript onClick属性使用Thym立叶。 我这样写代码 此代码正在运行。当productName包含这样的特殊字符时,我会遇到问题 然后JavaScript函数看起来像这样 我需要从产品名称中转义双引号和单引号字符。我该怎么做?

  • 我有一个具有两个实体的应用程序,它们具有双向一对多关系。车主和自行车。 因此,通过curl获得所有者将 这很好。 如果我创建一个在表中循环的模板, 然后我在浏览器中得到了预期的结果。我意识到上面的代码很糟糕,但我现在只对让thymeleaf工作感兴趣。 但是如果我执行以下代码 然后我得到以下控制台错误 嵌套的异常是org。百里香。例外情况。TemplateProcessingException:异

  • 我试图从这个胸腺页发送一个参数 然后我尝试使用此代码接收参数() 问题是当的值类似于我在方法中收到的makeAndSendInVoice只是 它不会向我发送部分 我该怎么修?