【问题标题】:Bean validation with no effects没有效果的 Bean 验证
【发布时间】:2012-12-04 12:20:00
【问题描述】:

当我在页面中单击“保存”时引入了验证后,没有任何反应。 在页面中,我有“保存”和“取消”。我将“immediate=true”设置为取消按钮,这样就不会执行任何验证,它会按预期返回到上一个视图。 当我单击保存时,将执行验证并正确显示错误,但是如果/当我输入正确的输入时(以便验证没有错误),而不是处理数据并返回上一页,什么也没有发生...

我错过了什么吗?

这里有一些代码sn-ps:

查看:

<f:metadata>
  <f:viewParam name="mode" value="#{roomDetailController.model.mode}"/>
  <f:viewParam name="dbId" value="#{roomDetailController.model.dbId}"/>

  <f:event listener="#{roomDetailController.processCommand}" type="preRenderView"/>
</f:metadata>

...

<tr>
  <td>
    <h:outputLabel value="#{msg.roomFormFieldRoomName}:"/>
  </td>
  <td>
    <h:inputText id="roomName" value="#{detailModel.afterObject.roomName}" disabled="#{detailModel.mode == detailModel.viewMode}">
      <f:validateBean/>
    </h:inputText>
    <h:message for="roomName" style="color:red"/><br/>
  </td>
</tr>
<tr>
  <td>
    <h:outputLabel value="#{msg.roomFormFieldRoomIPs}:"/>
  </td>
  <td>
    <h:inputText id="roomIPs" value="#{detailModel.afterObject.roomIPs}" disabled="#{detailModel.mode == detailModel.viewMode}">
      <f:validateBean/>
    </h:inputText>
    <h:message for="roomIPs" style="color:red"/><br/>
  </td>
</tr>

...

<!-- SUBMIT BUTTON -->
<h:commandButton
  styleClass     = "waiButton"
  value          = "#{commonButtonSubmit}"
  action         = "#{detailController.submitAction()}"
  rendered       = "#{detailModel.mode != detailModel.viewMode}"
/>

<!-- CANCEL BUTTON -->
<h:commandButton
  styleClass = "waiButton"
  value      = "#{commonButtonCancel}"
  action     = "#{detailController.cancelAction()}"
  immediate  = "true"
  rendered   = "#{detailModel.mode == detailModel.cancelMode or detailModel.mode == detailModel.editMode or detailModel.mode == detailModel.multiEditMode or detailModel.mode == detailModel.createMode}"
/>
...

控制器:

...
// Action: "submit" clicked
public String submitAction()
{
  detailModel.setCommand( DetailModel.Command.SUBMIT );
  return null;
}

// Action: "cancel" clicked
public String cancelAction()
{
  if ( detailModel.getEditMode().equals( detailModel.getMode() ) )
  {
    detailModel.setMode( detailModel.getViewMode() );
    return null;
  }
  else
  {
    // Multi Edit Mode
    return appendUrlParameter( getListViewName(), FACES_REDIRECT_TRUE );
  }
}
...

如果您需要更多信息,请告诉我...

【问题讨论】:

  • 对不起,我认为问题与验证无关......

标签: jsf-2 bean-validation


【解决方案1】:

问题解决了。如前所述,它与验证无关。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    • 2020-09-04
    • 2014-05-13
    相关资源
    最近更新 更多