【问题标题】:The header value of the struts2 select tag does not repopulate when validation fails验证失败时不会重新填充 struts2 选择标记的标头值
【发布时间】:2016-03-17 14:19:58
【问题描述】:

我有以下<s:select> 标记用于状态下拉列表和由defaultStateId 确定的默认状态。

<s:select name = "stateId" 
            id = "chooseState" 
          list = "stateList" 
       listKey = "codeId" 
     listValue = "shortDescription"  
         value = "defaultStateId"  
     headerKey = "0" 
   headerValue = "-Select-" 
         class = "form-control" 
      tabindex = "12"/>

如果用户选择任何状态并且验证失败,则当错误显示在页面上时,他们选择的状态会重新填充在页面上(这是我想要的)。

但是如果他们选择headerValue-Select-,即使stateId0,当validate() 方法运行时它也不会重新填充。

为什么value="defaultId" 覆盖-Select- 的选择而不是任何状态的选择?任何帮助将不胜感激。

【问题讨论】:

  • 如果你使用-1而不是0作为headerKey是否有效?
  • defaultStateId 是固定的还是在execute() 方法中动态计算的?
  • 感谢您的提问,我发现了这个问题。如果 id 值为 0,getDefaultStateId() 方法会从代码表中返回 defaultStateId,因此它会覆盖“-Select-”选项。谢谢!。

标签: jsp struts2 struts-validation struts-tags repopulation


【解决方案1】:

将 headerKey 更改为“-1”。那应该可以解决它。

【讨论】:

  • 再解释一下就好了。
猜你喜欢
  • 1970-01-01
  • 2014-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-06
相关资源
最近更新 更多