开发者

Velocity evaluate expression to Boolean

开发者 https://www.devze.com 2023-03-11 09:35 出处:网络
Is there a way to simplify this assignmet in Velocity? #if($errors.contains(\"Field required.\") #set($requiredFieldErrors = true)

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

精彩评论

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

关注公众号