- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设在操作类中有一个 BigDecimal
类型的字段,如下所示。
@Namespace("/admin_side")
@ResultPath("/WEB-INF/content")
@ParentPackage(value = "struts-default")
public final class TestAction extends ActionSupport
{
private BigDecimal price;
//Setter and getter.
@Validations(
requiredFields = {
@RequiredFieldValidator(fieldName = "price", type = ValidatorType.FIELD, message = "Price is mandatory.")},
fieldExpressions = {
@FieldExpressionValidator(fieldName = "price", expression = "price>0", shortCircuit = true, message = "Price cannot be less than or equal to zero.")})
@Action(value = "Add",
results = {
@Result(name = ActionSupport.SUCCESS, type = "redirectAction", params = {"namespace", "/admin_side", "actionName", "Test"}),
@Result(name = ActionSupport.INPUT, location = "Test.jsp")},
interceptorRefs = {
@InterceptorRef(value = "defaultStack", params = {"params.acceptParamNames", "price", "validation.validateAnnotatedMethodOnly", "true"})
})
public String insert() {
return ActionSupport.SUCCESS;
}
//This method is worth nothing. It is used just to return an initial view on page load.
@Action(value = "Test",
results = {
@Result(name = ActionSupport.SUCCESS, location = "Test.jsp"),
@Result(name = ActionSupport.INPUT, location = "Test.jsp")},
interceptorRefs = {
@InterceptorRef(value = "defaultStack", params = {"params.acceptParamNames", "", "params.excludeMethods", "load", "validation.validateAnnotatedMethodOnly", "true"})})
public String load() throws Exception {
return ActionSupport.SUCCESS;
}
}
下面是表格。
<s:form namespace="/admin_side" action="Test" id="dataForm" name="dataForm">
<s:fielderror fieldName="price"/>
<s:textfield id="price" name="price"/>
<s:submit value="Submit" action="Add"/>
</s:form>
我要实现,
@RequiredFieldValidator
@FieldExpressionValidator
出现。一次应该出现一个转换错误或一个验证错误。
这可能吗?到目前为止,我确实没有正确理解 shortCircuit
属性的功能。
最佳答案
乍一看没见过这么多。但是看着 Type Conversion Error Handling我会说有一种方法可以处理转换错误。通过将转换 validator 添加到短路 validator 的配置中。 Short-circuit意味着如果这样的 validator 有错误,其他 validator 将被跳过。
conversionErrorFields = @ConversionErrorFieldValidator(fieldName = "price", message = "Price has invalid value", shortCircuit = true)
将此代码放在 @Validations
注释下。
关于java - Struts2验证短路,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21050502/
考虑 function foo(x) x isa Bar || throw(ArgumentError("x is not a Int64...")) dosomething(x) e
这个问题在这里已经有了答案: AndAlso/OrElse in VBA (8 个回答) 7年前关闭。 VBA 不会短路 VBA 不支持短路 - 显然是因为它只有按位 And/Or/Not 等操作。来
这个问题在这里已经有了答案: Java operator precedence guidelines (6 个答案) 关闭 7 年前。 你好,我有一个关于 java 中的优先级表的问题。它说 &&
a &= foo(); 只是被 C++ 中的 a = a && foo(); 取代还是还有更多内容? 我关心的是 foo() 的计算。如果 a 为假,它会被调用吗? 最佳答案 && 是否有嵌入式短路:
我正在尝试注释以下代码。 当同时定义了 zone 和 zones 时,或者当定义了 file 时(但不是同时定义了两者),该函数将起作用: def get_file(zone: str, zones:
给定远程beam.smp服务的已知TCP端口和名称,以及已知的cookie,是否可以短路Erlang分发协议(protocol)的Erlang端口映射器守护进程握手阶段并直接建立Erlang shel
我正在尝试注释以下代码。 当同时定义了 zone 和 zones 时,或者当定义了 file 时(但不是同时定义了两者),该函数将起作用: def get_file(zone: str, zones:
我需要从第二个表中查询数据,但前提是满足主表中的一组罕见条件: SELECT ..., IF(a AND b AND c AND (SELECT 1 FROM tableb ...)) FROM ta
如标题所述,我想将 onchange 短路(在选择内部)。我有以下代码,但我只想发送一个硬编码值而不显示选择框。 "> [编辑] 对不起,我不清楚。我什至不想提供
我是 C++ 的新手,很好奇编译器如何处理 bool 值的惰性求值。例如, if(A == 1 || B == 2){...} 如果 A 确实等于 1,那么 B==2 部分是否曾经计算过? 最佳答案
我在尝试让这个 linq 语句起作用时遇到了一些麻烦。我正在使用 linq 查询设置搜索。我想要做的是,如果搜索为空或为空,让它忽略过滤的那一部分。所以我设置了很多 where 子句来缩短 where
这个问题在这里已经有了答案: How to short-circuit a reduce() operation on a Stream? (4 个答案) 关闭 4 年前。 在做项目的时候写了这行,
首先,我不是 Bash 专家。几个月前我发现,如果我同时使用 && 和 || 短路运算符和花括号,那么如果第一个语句以真实值退出,如果 true block 中的最后一条语句退出非零,那么 fail
我有一个使用逻辑 OR 运算符的 NSPredicate,如下所示: NSPredicate(format: "activeFrom == NULL OR %@ >= activeFrom", som
我是 C++ 的新手,很好奇编译器如何处理 bool 值的惰性求值。例如, if(A == 1 || B == 2){...} 如果 A 确实等于 1,那么 B==2 部分是否曾经计算过? 最佳答案
我需要从第二个表中查询数据,但前提是满足主表中的一组罕见条件: SELECT ..., IF(a AND b AND c AND (SELECT 1 FROM tableb ...)) FROM ta
我遇到了这段代码: 我想我们可以归纳为: 然后我找到了这个 article on short circuits和另一个 more focused one一旦我知道他们叫什么。但是,我还是不明白。
据我了解和阅读,您可以在 if 语句(&& 或 ||)中使用短路,以使第二个条件不触发。如果您希望两个条件都触发,您可以使用单个操作数(& 或 |)。 假设我有如下内联 if 语句: var test
在玩弄编译时字符串(char 的可变参数列表)操作时,我需要实现一种方法来检查编译时字符串是否包含另一个(较小的)编译时字符串。 这是我的第一次尝试: template struct Contains
如果我有以下... a OrElse b ... 并且 a 是 真那么显然 b 永远不会被评估。但是如果我添加一个 Or ,然后呢? a OrElse b Or c c 是否/应该得到评估?如果我放入
我是一名优秀的程序员,十分优秀!