use of javax.faces.application.FacesMessage in project acs-community-packaging by Alfresco.
the class LoginBean method validateMatch.
// ------------------------------------------------------------------------------
// Validator methods
/**
* Validate that field "confirm" matches to the field "password"
*/
public void validateMatch(FacesContext context, UIComponent component, Object value) throws ValidatorException {
String confirm = (String) value;
String field1Id = (String) component.getAttributes().get("passwd1Id");
UIInput passComponent = (UIInput) context.getViewRoot().findComponent(field1Id);
String pass = (String) passComponent.getSubmittedValue();
if (pass == null) {
pass = (String) passComponent.getValue();
}
if (!pass.equals(confirm)) {
String err = Application.getMessage(context, UsersDialog.ERROR_PASSWORD_MATCH);
throw new ValidatorException(new FacesMessage(err));
}
}
use of javax.faces.application.FacesMessage in project acs-community-packaging by Alfresco.
the class ClipboardBean method addClipboardNode.
/**
* Add a clipboard node to the clipboard ready for a cut/copy operation
*
* @param ref NodeRef of the item for the operation
* @param parent Parent of the item for the operation
* @param mode ClipboardStatus for the operation
*/
private void addClipboardNode(NodeRef ref, NodeRef parent, ClipboardStatus mode) {
// construct item based on store protocol
ClipboardItem item = null;
if (StoreRef.PROTOCOL_WORKSPACE.equals(ref.getStoreRef().getProtocol())) {
item = new WorkspaceClipboardItem(ref, parent, mode, customPasteViewIds);
}
if (item != null) {
// check for duplicates first
boolean foundDuplicate = false;
for (int i = 0; i < items.size(); i++) {
if (items.get(i).equals(item)) {
// found a duplicate replace with new instance as copy mode may have changed
items.set(i, item);
foundDuplicate = true;
break;
}
}
// if duplicate not found, then append to list
if (foundDuplicate == false) {
items.add(item);
}
// add a message to inform the user of the clipboard state now if configured
FacesContext context = FacesContext.getCurrentInstance();
if (Application.getClientConfig(context).isClipboardStatusVisible()) {
String pattern = Application.getMessage(context, "node_added_clipboard");
String msg = MessageFormat.format(pattern, items.size());
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
context.addMessage(null, facesMsg);
}
}
}
use of javax.faces.application.FacesMessage in project acs-community-packaging by Alfresco.
the class ErrorsRenderer method encodeBegin.
/**
* @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
if (component.isRendered() == false) {
return;
}
Iterator messages = context.getMessages();
if (messages.hasNext()) {
ResponseWriter out = context.getResponseWriter();
String contextPath = context.getExternalContext().getRequestContextPath();
String styleClass = (String) component.getAttributes().get("styleClass");
String errorClass = (String) component.getAttributes().get("errorClass");
if (errorClass == null) {
errorClass = DEFAULT_CSS_ERROR;
}
String infoClass = (String) component.getAttributes().get("infoClass");
if (infoClass == null) {
infoClass = DEFAULT_CSS_INFO;
}
String message = (String) component.getAttributes().get("message");
String errorHint = Application.getMessage(context, ERROR_HINT);
if (message == null) {
// because we are using the standard messages component value binding
// would not be handled for the message attribute so do it here
ValueBinding vb = component.getValueBinding("message");
if (vb != null) {
message = (String) vb.getValue(context);
}
if (message == null) {
message = Application.getMessage(context, DEFAULT_MESSAGE);
}
}
PanelGenerator.generatePanelStart(out, contextPath, "yellowInner", "#ffffcc");
out.write("\n<div");
if (styleClass != null) {
outputAttribute(out, styleClass, "class");
}
out.write(">");
// if we have a message to display show it next to the info icon
if (message.length() > 0 && context.getMaximumSeverity().compareTo(FacesMessage.SEVERITY_WARN) > 0) {
out.write("<img src='");
out.write(contextPath);
out.write("/images/icons/info_icon.gif' alt='");
out.write(Utils.encode(errorHint));
out.write("' align='absmiddle'/> ");
out.write(Utils.encode(message));
out.write("\n<ul style='margin:2px;'>");
while (messages.hasNext()) {
FacesMessage fm = (FacesMessage) messages.next();
out.write("<li");
renderMessageAttrs(fm, out, errorClass, infoClass);
out.write(">");
out.write(Utils.encode(fm.getDetail()));
out.write("</li>\n");
}
out.write("</ul>");
} else {
// if there is no title message to display use a table to place
// the info icon on the left and the list of messages on the right
out.write("<table border='0' cellpadding='3' cellspacing='0'><tr><td valign='top'><img src='");
out.write(contextPath);
out.write("/images/icons/info_icon.gif' alt='");
out.write(Utils.encode(errorHint));
out.write("'/>");
out.write("</td><td>");
while (messages.hasNext()) {
FacesMessage fm = (FacesMessage) messages.next();
out.write("<div style='margin-bottom: 3px;'");
renderMessageAttrs(fm, out, errorClass, infoClass);
out.write(">");
out.write(Utils.encode(fm.getDetail()));
out.write("</div>\n");
}
out.write("</td></tr></table>");
}
out.write("</div>\n");
PanelGenerator.generatePanelEnd(out, contextPath, "yellowInner");
// TODO: Expose this as a configurable attribute i.e. padding at bottom
out.write("<div style='padding:2px;'></div>");
}
}
use of javax.faces.application.FacesMessage in project acs-community-packaging by Alfresco.
the class CreateUserWizard method validateUsername.
/**
* Validate Username field data is acceptable
*/
public void validateUsername(FacesContext context, UIComponent component, Object value) throws ValidatorException {
int minUsernameLength = Application.getClientConfig(context).getMinUsernameLength();
String name = ((String) value).trim();
if (name.length() < minUsernameLength || name.length() > 256) {
String err = MessageFormat.format(Application.getMessage(context, LoginBean.MSG_USERNAME_LENGTH), new Object[] { minUsernameLength, 256 });
throw new ValidatorException(new FacesMessage(err));
}
if (name.indexOf('"') != -1 || name.indexOf('\\') != -1) {
String err = MessageFormat.format(Application.getMessage(context, LoginBean.MSG_USER_ERR), new Object[] { "\", \\" });
throw new ValidatorException(new FacesMessage(err));
}
try {
name = PersonServiceImpl.updateUsernameForTenancy(name, getTenantService());
} catch (TenantDomainMismatchException e) {
String err = MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), ERROR_DOMAIN_MISMATCH), e.getTenantA(), e.getTenantB());
throw new ValidatorException(new FacesMessage(err));
}
}
use of javax.faces.application.FacesMessage in project acs-community-packaging by Alfresco.
the class CreateUserWizard method validateEmail.
/**
* Validate Email field data is acceptable
*
* @param context FacesContext
* @param component UIComponent
* @param value Object
* @throws ValidatorException
*/
public void validateEmail(FacesContext context, UIComponent component, Object value) throws ValidatorException {
String emailRegExp = Application.getClientConfig(context).getEmailRegExp();
Pattern pattern = Pattern.compile(emailRegExp, Pattern.CASE_INSENSITIVE);
if (!pattern.matcher((CharSequence) value).matches()) {
String err = Application.getMessage(context, MSG_ERROR_MAIL_NOT_VALID);
throw new ValidatorException(new FacesMessage(err));
}
}
Aggregations