开发者

Velocity evaluate expression to Boolean

Is there a way to simplify this assignmet in Velocity?

#if($errors.contains("Field required.")
    #set($requiredFieldErrors = true)
#else
    #set($requiredFieldErrors = false)
#end

So I need the $requiredFieldErrors as boolean so I can use the value later on in a if-else statement. A definit开发者_StackOverflow社区ion in one line would be great.


You can modify this to:

#set($reqField = $errors.contains("Field Required.")

Or directly test it in the if statement (assuming you're not using the $reqField reference in other places).

Edit:

#set($reqField = $errors && $errors.contains("Field Required.")

The above line will check to make sure $errors is a valid reference and contains the required value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜