Spring验证错误标记无法完全与Webflow + Portlet一起使用 [英] Spring validation errors tag not working completely with webflow + portlet

查看:93
本文介绍了Spring验证错误标记无法完全与Webflow + Portlet一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小项目(使用Spring 4.2.0,Spring Webflow 2.4.2,Hibernate验证器5.2.2),该项目在servlet世界中按预期工作,但是在将其转换为Portlet之后,验证反馈在JSP不再能够完全按预期运行.

I have a small project (using Spring 4.2.0, Spring Webflow 2.4.2, Hibernate validator 5.2.2) that is working as expected in the servlet world, but after having transformed it to a portlet, the validation feedback in JSP doesn't work fully as expected anymore.

对于如下形式的表单:

<form:form modelAttribute="person" action="${flowExecutionUrl}">
    <form:input path="voornaam"/>
    ....
</form:form>

这在portlet中仍然有效(因此我至少得到确认已触发我的验证错误的确认):

This still works in the portlet (so I get at least the confirmation that my validation error has been triggered):

  <form:errors path="*" />
  <form:errors path="voornaam" />

这可以正确呈现:

<span id="person.errors">may not be empty</span>
<span id="voornaam.errors">may not be empty</span>

但是<form:error />的此变体,其中<form:error>标记的 contents 应该在出现错误的情况下呈现,停止工作并且不呈现:

But this variant of the <form:error />, where the contents of the <form:error> tag should be rendered in case of errors, stopped working and is not rendered:

<form:errors path="*">
    <p>Should only show in case of any errors</p>
</form:errors>

日志中的一些调试消息:

Some of the debug messages in the log:

2016-02-23 15:18:36 DEBUG DefaultMessageContext:116 - Resolving message using [DefaultMessageResolver@3a13a7e3 source = 'voornaam', severity = ERROR, codes = array<String>['person.voornaam.NotBlank', 'voornaam.NotBlank', 'java.lang.String.NotBlank', 'NotBlank'], args = array<Object>[org.springframework.context.support.DefaultMessageSourceResolvable: codes [person.voornaam,voornaam]; arguments []; default message [voornaam]], defaultText = 'may not be empty']
2016-02-23 15:18:37 DEBUG SessionBindingConversationManager:86 - Putting conversation attribute 'scope' with value map['flashScope' -> map['viewUserEventState' -> [ViewActionStateHolder@6c38a8f7 eventId = 'save', mappingResults = Mapping Results = [[TargetAccessError@1c127930 mapping = parameter:'execution' -> execution, code = 'propertyNotFound', error = true, errorCause = org.springframework.binding.expression.PropertyNotFoundException: Property not found, originalValue = 'e1s2', mappedValue = [null]], [Success@67b8b31e mapping = parameter:'achternaam' -> achternaam, code = 'success', error = false, originalValue = 'Prefab achternaam', mappedValue = 'Prefab achternaam'], [Success@6083383d mapping = parameter:'tussenvoegsel' -> tussenvoegsel, code = 'success', error = false, originalValue = '', mappedValue = ''], [Success@5fc92799 mapping = parameter:'voornaam' -> voornaam, code = 'success', error = false, originalValue = '', mappedValue = '']]], 'messagesMemento' -> map[[null] -> list[[empty]], 'voornaam' -> list[[Message@5a930a7c source = 'voornaam', severity = ERROR, text = 'may not be empty']]]]]
2016-02-23 15:18:37 DEBUG AbstractMvcView:194 - Rendering MVC [org.springframework.web.servlet.view.JstlView: unnamed; URL [/WEB-INF/flows/editPersonDetails.jsp]] with model map [{viewUserEventState=[ViewActionStateHolder@6c38a8f7 eventId = 'save', mappingResults = Mapping Results = [[TargetAccessError@1c127930 mapping = parameter:'execution' -> execution, code = 'propertyNotFound', error = true, errorCause = org.springframework.binding.expression.PropertyNotFoundException: Property not found, originalValue = 'e1s2', mappedValue = [null]], [Success@67b8b31e mapping = parameter:'achternaam' -> achternaam, code = 'success', error = false, originalValue = 'Prefab achternaam', mappedValue = 'Prefab achternaam'], [Success@6083383d mapping = parameter:'tussenvoegsel' -> tussenvoegsel, code = 'success', error = false, originalValue = '', mappedValue = ''], [Success@5fc92799 mapping = parameter:'voornaam' -> voornaam, code = 'success', error = false, originalValue = '', mappedValue = '']]], org.springframework.validation.BindingResult.person=org.springframework.webflow.mvc.view.BindingModel: 1 errors
Field error in object 'person' on field 'voornaam': rejected value [null]; codes []; arguments []; default message [may not be empty], masterData={tussenvoegsel=[, de...]}, currentUser=10201, viewScope=map[[empty]], flowExecutionKey=e1s2, flowExecutionUrl=http://localhost:8080/web/guest/person-details?p_auth=Cknp0vsP&p_p_id=webflowportlet_WAR_webflowpoc10SNAPSHOT&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_webflowportlet_WAR_webflowpoc10SNAPSHOT_execution=e1s2, person=Person{voornaam='', achternaam='Prefab achternaam', tussenvoegsel=''}, flashScope=map['viewUserEventState' -> [ViewActionStateHolder@6c38a8f7 eventId = 'save', mappingResults = Mapping Results = [[TargetAccessError@1c127930 mapping = parameter:'execution' -> execution, code = 'propertyNotFound', error = true, errorCause = org.springframework.binding.expression.PropertyNotFoundException: Property not found, originalValue = 'e1s2', mappedValue = [null]], [Success@67b8b31e mapping = parameter:'achternaam' -> achternaam, code = 'success', error = false, originalValue = 'Prefab achternaam', mappedValue = 'Prefab achternaam'], [Success@6083383d mapping = parameter:'tussenvoegsel' -> tussenvoegsel, code = 'success', error = false, originalValue = '', mappedValue = ''], [Success@5fc92799 mapping = parameter:'voornaam' -> voornaam, code = 'success', error = false, originalValue = '', mappedValue = '']]]], flowRequestContext=[RequestControlContextImpl@77af2f59 externalContext = org.springframework.webflow.context.portlet.PortletExternalContext@603391cf, currentEvent = [null], requestScope = map[[empty]], attributes = map[[empty]], messageContext = [DefaultMessageContext@5ef95b61 sourceMessages = map[[null] -> list[[empty]], 'voornaam' -> list[[Message@5a930a7c source = 'voornaam', severity = ERROR, text = 'may not be empty']]]], flowExecution = [FlowExecutionImpl@bee658a flow = 'personDetails', flowSessions = list[[FlowSessionImpl@3ac3099f flow = 'personDetails', state = 'editPersonDetails', scope = map['masterData' -> map['tussenvoegsel' -> list['', 'de', 'den', 'ten', 'ter', 'uit', 'van', 'van de', 'van den', 'van der']], 'viewScope' -> map[[empty]], 'person' -> Person{voornaam='', achternaam='Prefab achternaam', tussenvoegsel=''}]]]]]}]

我已经无济于事:

  • container-runtime-option,其中javax.portlet.actionScopedRequestAttributes设置为true
  • 使用我的LocalValidatorFactoryBean
  • AnnotationMethodHandlerAdapterConfigurableWebBindingInitializer接线
  • 使用官方示例项目 booking-portlet-mvc ,它显示了相同的错误. (我在enterBookingDetails.jsp上添加了<form:errors path="checkinDate">only shown on error</form:errors>行,但未渲染)
  • container-runtime-option with javax.portlet.actionScopedRequestAttributes set to true
  • Wiring a AnnotationMethodHandlerAdapter with ConfigurableWebBindingInitializer using my LocalValidatorFactoryBean
  • Reproducing the same behaviour with the official sample project booking-portlet-mvc, which showed the same error. (I added a line <form:errors path="checkinDate">only shown on error</form:errors> to enterBookingDetails.jsp which does not render)

关于servlet和portlet世界之间的差异的任何线索可能会导致这种情况? 还是在调试时在哪里寻找的任何提示?

Any clues on differences between the servlet and portlet world that might cause this? Or any hints on where to look for in debugging this?

推荐答案

目前,我有一个可行的解决方法(尽管不太优雅). 我创建了一个这样的自定义JSP标记:

For now I have a workaround that is functional (albeit slightly less elegant). I created a custom JSP tag like this:

<%@ attribute name="path" required="true" type="java.lang.String" description="The path, or a wildcard '*'" %>
<spring:bind path="${path}">
    <c:if test="${status.errors.errorCount > 0}">
        <jsp:doBody />
    </c:if>
</spring:bind>

这篇关于Spring验证错误标记无法完全与Webflow + Portlet一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆