use of javax.faces.application.FacesMessage in project deltaspike by apache.
the class JsfUtilsTest method testExistingMessageWithoutSummary.
@Test
public void testExistingMessageWithoutSummary() {
List<FacesMessage> existingFacesMessage = new ArrayList<FacesMessage>();
existingFacesMessage.add(new FacesMessage(null, "test"));
FacesMessage messageToCheck = new FacesMessage(null, "test");
Assert.assertEquals(Boolean.FALSE, JsfUtils.isNewMessage(existingFacesMessage, messageToCheck));
}
use of javax.faces.application.FacesMessage in project deltaspike by apache.
the class JsfUtilsTest method testNewMessageWithoutSummary.
@Test
public void testNewMessageWithoutSummary() {
List<FacesMessage> existingFacesMessage = new ArrayList<FacesMessage>();
existingFacesMessage.add(new FacesMessage("existing", "message"));
FacesMessage messageToCheck = new FacesMessage(null, "test");
Assert.assertEquals(Boolean.TRUE, JsfUtils.isNewMessage(existingFacesMessage, messageToCheck));
}
use of javax.faces.application.FacesMessage in project oxCore by GluuFederation.
the class FacesMessages method add.
public void add(String clientId, Severity severity, String message) {
if (facesContext == null) {
return;
}
String evaluatedMessage = evalAsString(message);
String encodedMessage = StringEscapeUtils.escapeHtml4(evaluatedMessage);
FacesMessage facesMessage = new FacesMessage(severity, encodedMessage, encodedMessage);
facesContext.addMessage(clientId, facesMessage);
messages.put(clientId, facesMessage);
setKeepMessages();
}
use of javax.faces.application.FacesMessage in project oxCore by GluuFederation.
the class AttributeValidator method validate.
@Override
public void validate(FacesContext context, UIComponent comp, Object value) {
GluuAttribute attribute = (GluuAttribute) comp.getAttributes().get("attribute");
if (attribute == null) {
((UIInput) comp).setValid(true);
return;
}
AttributeValidation attributeValidation = attribute.getAttributeValidation();
Integer minvalue = attributeValidation != null ? attributeValidation.getMinLength() : null;
Integer maxValue = attributeValidation != null ? attributeValidation.getMaxLength() : null;
String regexpValue = attributeValidation != null ? attributeValidation.getRegexp() : null;
String attributeValue = (String) value;
// Minimum length validation
if (minvalue != null) {
int min = attributeValidation.getMinLength();
if ((attributeValue != null) && (attributeValue.length() < min)) {
((UIInput) comp).setValid(false);
FacesMessage message = new FacesMessage(attribute.getDisplayName() + " should be at least " + min + " symbols. ");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(comp.getClientId(context), message);
}
}
// default maxlength
int max = 400;
if (maxValue != null) {
max = attributeValidation.getMaxLength();
}
// Maximum Length validation
if ((attributeValue != null) && (attributeValue.length() > max)) {
((UIInput) comp).setValid(false);
FacesMessage message = new FacesMessage(attribute.getDisplayName() + " should not exceed " + max + " symbols. ");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(comp.getClientId(context), message);
}
if ((attribute.getName().equalsIgnoreCase("mail") && ((regexpValue == null) || (StringHelper.isEmpty(regexpValue))))) {
regexpValue = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" + "[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$";
}
if ((regexpValue != null) && StringHelper.isNotEmpty(regexpValue)) {
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regexpValue);
if ((attributeValue != null) && !(attributeValue.trim().equals(""))) {
java.util.regex.Matcher matcher = pattern.matcher(attributeValue);
boolean flag = matcher.matches();
if (!flag) {
((UIInput) comp).setValid(false);
FacesMessage message = new FacesMessage(attribute.getDisplayName() + " Format is invalid. ");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(comp.getClientId(context), message);
}
}
}
}
use of javax.faces.application.FacesMessage in project Payara by payara.
the class Game method check.
public String check() throws InterruptedException {
System.out.println("In Game::check");
sb.hello();
if (guess > number) {
biggest = guess - 1;
}
if (guess < number) {
smallest = guess + 1;
}
if (guess == number) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Correct!"));
}
remainingGuesses--;
return null;
}
Aggregations