-
-
Save awildturtok/0272344c38c29beb2de64988282fd2e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package conf; | |
import com.fizzed.rocker.RockerContent; | |
import com.fizzed.rocker.RockerModel; | |
import ninja.validation.Validation; | |
import java.util.Objects; | |
import java.util.Optional; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
/** | |
* Created by fk on 04.04.2016. | |
*/ | |
public abstract class MyRockerTemplate extends com.fizzed.ninja.rocker.NinjaRockerTemplate | |
{ | |
public MyRockerTemplate(RockerModel model) | |
{ | |
super(model); | |
} | |
public String ifTrue(boolean value, String content) | |
{ | |
return value ? content : ""; | |
} | |
public RockerContent ifTrue(boolean value, RockerContent content) | |
{ | |
return value ? content : RockerContent.NONE; | |
} | |
public boolean hasViolation(Validation validation, String key) | |
{ | |
return Stream.concat(validation.getBeanViolations().stream(), validation.getFieldViolations().stream()) | |
.anyMatch(fv -> fv.field.equalsIgnoreCase(key)); | |
} | |
public static String renderViolations(Validation validation, String key) | |
{ | |
return Stream.concat(validation.getBeanViolations().stream(), validation.getFieldViolations().stream()) | |
.filter(fv -> fv.field.equalsIgnoreCase(key)) | |
.map(fv -> fv.constraintViolation.getMessageKey()) | |
.collect(Collectors.joining("<br />")); | |
} | |
public String toString(Optional<?> object) | |
{ | |
return toString(object.map(Object::toString).orElse(null), ""); | |
} | |
public String toString(Object object) | |
{ | |
return toString(object, ""); | |
} | |
public String toString(Object object, String dflt) | |
{ | |
return Objects.toString(object, dflt); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment