我和春天4.0.7和Spring Web Flow 2.4.0Spring Web Flow的LocalValidatorFactoryBean(JSR-349)不工作怎麼有望
我有以下的(我與JSR 349
工作)工作:
對於實體:
@Min(value=1, message="{person.age.min}",groups={PersonRegistrationCheck.class})
@Max(value=115, message="{person.age.max}",groups={PersonRegistrationCheck.class})
@NotNull(message="{field.null}",groups={PersonRegistrationCheck.class})
@Column(name="age", nullable=false, length=3)
@XmlElement
public Integer getAge() {
return age;
}
在ValidationMessages.properties
文件
person.age.max = Invalid data '${validatedValue}', the maximum value allowed is {value}
person.age.min = Invalid data '${validatedValue}', the minimum value allowed is {value}
在一些@Configuration
@Bean
public LocalValidatorFactoryBean localValidatorFactoryBean(ReloadableResourceBundleMessageSource messageSource){
LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
localValidatorFactoryBean.setValidationMessageSource(messageSource);
MessageSourceResourceBundleLocator msrbl = new MessageSourceResourceBundleLocator(messageSource);
ResourceBundleMessageInterpolator rbmi = new ResourceBundleMessageInterpolator(msrbl);
localValidatorFactoryBean.setMessageInterpolator(rbmi);
return localValidatorFactoryBean;
}
通過Spring MVC的它工作完全正常:
<tr>
<td><spring:message code="person.form.age"/></td>
<td><form:input path="age" size="40"/></td>
<td><form:errors path="age" cssClass="error"/></td>
</tr>
如果我把一個無效值怎麼500弄
無效數據500,最大值允許是115
我可以看到我無效的數據和允許的最大值。
直到這裏一切都OK ..
注意:是不必要做一下LocalValidatorFactoryBean
爲Spring MVC
一個特殊的注射問題是與Spring Web Flow的。
注意:是必要爲Spring Web Flow
這裏它的配置做一下LocalValidatorFactoryBean
一個特殊的注射:
@Autowired
private LocalValidatorFactoryBean localValidatorFactoryBean;
@Bean
public FlowBuilderServices flowBuilderServices() {
return getFlowBuilderServicesBuilder()
.setViewFactoryCreator(mvcViewFactoryCreator())
.setConversionService(conversionService())
.setValidator(localValidatorFactoryBean)
.setDevelopmentMode(true)
.build();
}
以上是幾乎幾乎同樣與根據spring-webflow-samples /WebFlowConfig
在流程defini中重刑
<view-state id="start"
view="person.flow.form.register"
model="person"
validation-hints="'com.manuel.jordan...PersonRegistrationCheck'" >
<transition on="submit" to="address" bind="true" validate="true" >
<evaluate expression="personAction.savePerson(flowRequestContext)" />
</transition>
<transition on="cancel" to="end" bind="false" validate="false"/>
</view-state>
再在.jsp文件
<tr>
<td><spring:message code="person.form.age"/></td>
<td><form:input path="age" size="40"/></td>
<td><form:errors path="age" cssClass="error"/></td>
</tr>
注意:這是其他或新的.jsp文件,它爲Spring Web Flow的工作。 因此一個工作通過Spring MVC
和其他SWF
。 它用於測試目的
好的問題:
同樣如果我把一個無效值怎麼500弄
無效數據$ validatedValue,允許的最大值是價值
觀察:我們不能看到,無效數據(仍以$ validatedValue)和value
仍然如何靜態。
因此:
Spring MVC
顯示:Invalid data 500, the maximum value allowed is 115
SWF
顯示:Invalid data $validatedValue, the maximum value allowed is value
注意:即使使用以下,所有出問題呢。
@Bean
public LocalValidatorFactoryBean localValidatorFactoryBean(ReloadableResourceBundleMessageSource messageSource){
LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
localValidatorFactoryBean.setValidationMessageSource(messageSource);
//MessageSourceResourceBundleLocator msrbl = new MessageSourceResourceBundleLocator(messageSource);
//ResourceBundleMessageInterpolator rbmi = new ResourceBundleMessageInterpolator(msrbl);
//localValidatorFactoryBean.setMessageInterpolator(rbmi);
return localValidatorFactoryBean;
}
什麼是錯誤或缺失?
謝謝Rossen。讓我測試一下,這個週末。 – 2015-08-05 17:18:01