package com.vaadin.data;
import java.io.Serializable;
-import java.util.Collections;
-import java.util.List;
import com.vaadin.data.Validator.InvalidValueException;
-import com.vaadin.terminal.ErrorMessage;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.SystemError;
-import com.vaadin.terminal.gwt.client.communication.SharedState;
-import com.vaadin.terminal.gwt.server.ClientMethodInvocation;
/**
* <p>
*/
@SuppressWarnings("serial")
public class SourceException extends RuntimeException implements
- ErrorMessage, Serializable {
+ Serializable {
/** Source class implementing the buffered interface */
private final Buffered source;
/**
* Gets the cause of the exception.
*
- * @return The cause for the exception.
- * @throws MoreThanOneCauseException
- * if there is more than one cause for the exception. This
- * is possible if the commit operation triggers more than
- * one error at the same time.
+ * @return The (first) cause for the exception, null if no cause.
*/
@Override
public final Throwable getCause() {
return source;
}
- /**
- * Gets the error level of this buffered source exception. The level of
- * the exception is maximum error level of all the contained causes.
- * <p>
- * The causes that do not specify error level default to
- * <code>ERROR</code> level. Also source exception without any causes
- * are of level <code>ERROR</code>.
- * </p>
- *
- * @see com.vaadin.terminal.ErrorMessage#getErrorLevel()
- */
- public ErrorLevel getErrorLevel() {
-
- ErrorLevel level = null;
-
- for (int i = 0; i < causes.length; i++) {
- final ErrorLevel causeLevel = (causes[i] instanceof ErrorMessage) ? ((ErrorMessage) causes[i])
- .getErrorLevel() : ErrorLevel.ERROR;
- if (level == null) {
- level = causeLevel;
- } else {
- if (causeLevel.intValue() > level.intValue()) {
- level = causeLevel;
- }
- }
- }
-
- return level == null ? ErrorLevel.ERROR : level;
- }
-
- /* Documented in super interface */
- public void paint(PaintTarget target) throws PaintException {
- target.startTag("error");
- target.addAttribute("level", getErrorLevel().getText());
-
- // Paint all the exceptions
- for (int i = 0; i < causes.length; i++) {
- if (causes[i] instanceof ErrorMessage) {
- ((ErrorMessage) causes[i]).paint(target);
- } else {
- new SystemError(causes[i]).paint(target);
- }
- }
-
- target.endTag("error");
-
- }
-
- public SharedState getState() {
- // TODO implement: move relevant parts from paint() to getState()
- return null;
- }
-
- public List<ClientMethodInvocation> retrievePendingRpcCalls() {
- return Collections.emptyList();
- }
-
- /* Documented in super interface */
- public void addListener(RepaintRequestListener listener) {
- }
-
- /* Documented in super interface */
- public void removeListener(RepaintRequestListener listener) {
- }
-
- /* Documented in super interface */
- public void requestRepaint() {
- }
-
- /* Documented in super interface */
- public void requestRepaintRequests() {
- }
-
- public String getDebugId() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void setDebugId(String id) {
- throw new UnsupportedOperationException(
- "Setting testing id for this Paintable is not implemented");
- }
-
}
}
package com.vaadin.data;
import java.io.Serializable;
-import java.util.Collections;
-import java.util.List;
-import com.vaadin.terminal.ErrorMessage;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.communication.SharedState;
import com.vaadin.terminal.gwt.server.AbstractApplicationServlet;
-import com.vaadin.terminal.gwt.server.ClientMethodInvocation;
/**
* Interface that implements a method for validating if an {@link Object} is
* @since 3.0
*/
@SuppressWarnings("serial")
- public class InvalidValueException extends RuntimeException implements
- ErrorMessage {
+ public class InvalidValueException extends RuntimeException {
/**
* Array of one or more validation errors that are causing this
return true;
}
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.terminal.ErrorMessage#getErrorLevel()
- */
- public final ErrorLevel getErrorLevel() {
- return ErrorLevel.ERROR;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.vaadin.terminal.Paintable#paint(com.vaadin.terminal.PaintTarget)
- */
- public void paint(PaintTarget target) throws PaintException {
- target.startTag("error");
- target.addAttribute("level", ErrorLevel.ERROR.getText());
-
- // Error message
- final String message = getHtmlMessage();
- if (message != null) {
- target.addText(message);
- }
-
- // Paint all the causes
- for (int i = 0; i < causes.length; i++) {
- causes[i].paint(target);
- }
-
- target.endTag("error");
- }
-
- public SharedState getState() {
- // TODO implement: move relevant parts from paint() to getState()
- return null;
- }
-
- public List<ClientMethodInvocation> retrievePendingRpcCalls() {
- return Collections.emptyList();
- }
-
/**
* Returns the message of the error in HTML.
*
* Note that this API may change in future versions.
*/
- protected String getHtmlMessage() {
+ public String getHtmlMessage() {
return AbstractApplicationServlet
.safeEscapeForHtml(getLocalizedMessage());
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.vaadin.terminal.ErrorMessage#addListener(com.vaadin.terminal.
- * Paintable.RepaintRequestListener)
- */
- public void addListener(RepaintRequestListener listener) {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.vaadin.terminal.ErrorMessage#removeListener(com.vaadin.terminal
- * .Paintable.RepaintRequestListener)
- */
- public void removeListener(RepaintRequestListener listener) {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.terminal.ErrorMessage#requestRepaint()
- */
- public void requestRepaint() {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.terminal.Paintable#requestRepaintRequests()
- */
- public void requestRepaintRequests() {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.terminal.Paintable#getDebugId()
- */
- public String getDebugId() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.terminal.Paintable#setDebugId(java.lang.String)
- */
- public void setDebugId(String id) {
- throw new UnsupportedOperationException(
- "InvalidValueException cannot have a debug id");
- }
-
/**
* Returns the {@code InvalidValueExceptions} that caused this
* exception.
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.data.Buffered;
+import com.vaadin.data.Validator;
+import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
+import com.vaadin.terminal.gwt.server.AbstractApplicationServlet;
+
+/**
+ * Base class for component error messages.
+ *
+ * This class is used on the server side to construct the error messages to send
+ * to the client.
+ *
+ * @since 7.0
+ */
+public abstract class AbstractErrorMessage implements ErrorMessage {
+
+ public enum ContentMode {
+ /**
+ * Content mode, where the error contains only plain text.
+ */
+ TEXT,
+ /**
+ * Content mode, where the error contains preformatted text.
+ */
+ PREFORMATTED,
+ /**
+ * Content mode, where the error contains XHTML.
+ */
+ XHTML;
+ }
+
+ /**
+ * Content mode.
+ */
+ private ContentMode mode = ContentMode.TEXT;
+
+ /**
+ * Message in content mode.
+ */
+ private String message;
+
+ /**
+ * Error level.
+ */
+ private ErrorLevel level = ErrorLevel.ERROR;
+
+ private List<ErrorMessage> causes = new ArrayList<ErrorMessage>();
+
+ protected AbstractErrorMessage(String message) {
+ this.message = message;
+ }
+
+ protected String getMessage() {
+ return message;
+ }
+
+ protected void setMessage(String message) {
+ this.message = message;
+ }
+
+ /* Documented in interface */
+ public ErrorLevel getErrorLevel() {
+ return level;
+ }
+
+ protected void setErrorLevel(ErrorLevel level) {
+ this.level = level;
+ }
+
+ protected ContentMode getMode() {
+ return mode;
+ }
+
+ protected void setMode(ContentMode mode) {
+ this.mode = mode;
+ }
+
+ protected List<ErrorMessage> getCauses() {
+ return causes;
+ }
+
+ protected void addCause(ErrorMessage cause) {
+ causes.add(cause);
+ }
+
+ @Deprecated
+ public void paint(PaintTarget target) throws PaintException {
+
+ // TODO if no message and only one cause, paint cause only? error level?
+
+ target.startTag(AbstractComponentConnector.ATTRIBUTE_ERROR);
+ target.addAttribute("level", level.getText());
+
+ paintContent(target);
+
+ target.endTag(AbstractComponentConnector.ATTRIBUTE_ERROR);
+ }
+
+ // TODO temporary method - move logic to client side
+ @Deprecated
+ protected void paintContent(PaintTarget target) throws PaintException {
+ // Paint the message
+ switch (getMode()) {
+ case TEXT:
+ target.addText(AbstractApplicationServlet
+ .safeEscapeForHtml(getMessage()));
+ break;
+ case PREFORMATTED:
+ target.addText("<pre>"
+ + AbstractApplicationServlet
+ .safeEscapeForHtml(getMessage()) + "</pre>");
+ break;
+ case XHTML:
+ target.addText(getMessage());
+ break;
+ }
+
+ if (getCauses().size() > 0) {
+ for (ErrorMessage cause : getCauses()) {
+ cause.paint(target);
+ }
+ }
+ }
+
+ // TODO replace this with a helper method elsewhere?
+ public static ErrorMessage getErrorMessageForException(Throwable t) {
+ if (null == t) {
+ return null;
+ } else if (t instanceof ErrorMessage) {
+ // legacy case for custom error messages
+ return (ErrorMessage) t;
+ } else if (t instanceof Validator.InvalidValueException) {
+ UserError error = new UserError(
+ ((Validator.InvalidValueException) t).getHtmlMessage(),
+ ContentMode.XHTML, ErrorLevel.ERROR);
+ for (Validator.InvalidValueException nestedException : ((Validator.InvalidValueException) t)
+ .getCauses()) {
+ error.addCause(getErrorMessageForException(nestedException));
+ }
+ return error;
+ } else if (t instanceof Buffered.SourceException) {
+ // no message, only the causes to be painted
+ UserError error = new UserError(null);
+ // in practice, this was always ERROR in Vaadin 6 unless tweaked in
+ // custom exceptions implementing ErrorMessage
+ error.setErrorLevel(ErrorLevel.ERROR);
+ // causes
+ for (Throwable nestedException : ((Buffered.SourceException) t)
+ .getCauses()) {
+ error.addCause(getErrorMessageForException(nestedException));
+ }
+ return error;
+ } else {
+ return new SystemError(t);
+ }
+ }
+
+ /* Documented in superclass */
+ @Override
+ public String toString() {
+ return getMessage();
+ }
+
+}
package com.vaadin.terminal;
-import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
-
-import com.vaadin.terminal.gwt.client.communication.SharedState;
-import com.vaadin.terminal.gwt.server.ClientMethodInvocation;
/**
* Class for combining multiple error messages together.
* @since 3.0
*/
@SuppressWarnings("serial")
-public class CompositeErrorMessage implements ErrorMessage, Serializable {
-
- /**
- * Array of all the errors.
- */
- private final List<ErrorMessage> errors;
-
- /**
- * Level of the error.
- */
- private ErrorLevel level;
+public class CompositeErrorMessage extends AbstractErrorMessage {
/**
* Constructor for CompositeErrorMessage.
* ignored, but at least one message is required.
*/
public CompositeErrorMessage(ErrorMessage[] errorMessages) {
- errors = new ArrayList<ErrorMessage>(errorMessages.length);
- level = ErrorLevel.INFORMATION;
+ super(null);
+ setErrorLevel(ErrorLevel.INFORMATION);
for (int i = 0; i < errorMessages.length; i++) {
addErrorMessage(errorMessages[i]);
}
- if (errors.size() == 0) {
+ if (getCauses().size() == 0) {
throw new IllegalArgumentException(
"Composite error message must have at least one error");
}
*/
public CompositeErrorMessage(
Collection<? extends ErrorMessage> errorMessages) {
- errors = new ArrayList<ErrorMessage>(errorMessages.size());
- level = ErrorLevel.INFORMATION;
+ super(null);
+ setErrorLevel(ErrorLevel.INFORMATION);
for (final Iterator<? extends ErrorMessage> i = errorMessages
.iterator(); i.hasNext();) {
addErrorMessage(i.next());
}
- if (errors.size() == 0) {
+ if (getCauses().size() == 0) {
throw new IllegalArgumentException(
"Composite error message must have at least one error");
}
}
- /**
- * The error level is the largest error level in
- *
- * @see com.vaadin.terminal.ErrorMessage#getErrorLevel()
- */
- public final ErrorLevel getErrorLevel() {
- return level;
- }
-
/**
* Adds a error message into this composite message. Updates the level
* field.
* the error message to be added. Duplicate errors are ignored.
*/
private void addErrorMessage(ErrorMessage error) {
- if (error != null && !errors.contains(error)) {
- errors.add(error);
- if (error.getErrorLevel().intValue() > level.intValue()) {
- level = error.getErrorLevel();
+ if (error != null && !getCauses().contains(error)) {
+ addCause(error);
+ if (error.getErrorLevel().intValue() > getErrorLevel().intValue()) {
+ setErrorLevel(error.getErrorLevel());
}
}
}
* @return the error iterator.
*/
public Iterator<ErrorMessage> iterator() {
- return errors.iterator();
- }
-
- /**
- * @see com.vaadin.terminal.Paintable#paint(com.vaadin.terminal.PaintTarget)
- */
- public void paint(PaintTarget target) throws PaintException {
-
- if (errors.size() == 1) {
- (errors.iterator().next()).paint(target);
- } else {
- target.startTag("error");
- target.addAttribute("level", level.getText());
-
- // Paint all the exceptions
- for (final Iterator<ErrorMessage> i = errors.iterator(); i
- .hasNext();) {
- i.next().paint(target);
- }
-
- target.endTag("error");
- }
- }
-
- public SharedState getState() {
- // TODO implement: move relevant parts from paint() to getState()
- return null;
- }
-
- public List<ClientMethodInvocation> retrievePendingRpcCalls() {
- return Collections.emptyList();
- }
-
- /* Documented in super interface */
- public void addListener(RepaintRequestListener listener) {
- }
-
- /* Documented in super interface */
- public void removeListener(RepaintRequestListener listener) {
- }
-
- /* Documented in super interface */
- public void requestRepaint() {
- }
-
- /* Documented in super interface */
- public void requestRepaintRequests() {
+ return getCauses().iterator();
}
/**
public String toString() {
String retval = "[";
int pos = 0;
- for (final Iterator<ErrorMessage> i = errors.iterator(); i.hasNext();) {
+ for (final Iterator<ErrorMessage> i = getCauses().iterator(); i
+ .hasNext();) {
if (pos > 0) {
retval += ",";
}
return retval;
}
-
- public String getDebugId() {
- return null;
- }
-
- public void setDebugId(String id) {
- throw new UnsupportedOperationException(
- "Setting testing id for this Paintable is not implemented");
- }
}
* @VERSION@
* @since 3.0
*/
-public interface ErrorMessage extends Paintable, Serializable {
+public interface ErrorMessage extends Serializable {
public enum ErrorLevel {
/**
public ErrorLevel getErrorLevel();
/**
- * Error messages are inmodifiable and thus listeners are not needed. This
- * method should be implemented as empty.
+ * <p>
+ * Paints the error message into a UIDL stream. This method creates the UIDL
+ * sequence describing it and outputs it to the given UIDL stream.
+ * </p>
*
- * @param listener
- * the listener to be added.
- * @see com.vaadin.terminal.Paintable#addListener(Paintable.RepaintRequestListener)
+ * @param target
+ * the target UIDL stream where the error should paint itself to.
+ * @throws PaintException
+ * if the paint operation failed.
+ * @deprecated error messages should not be painted to UIDL but sent
+ * differently
*/
- public void addListener(RepaintRequestListener listener);
-
- /**
- * Error messages are inmodifiable and thus listeners are not needed. This
- * method should be implemented as empty.
- *
- * @param listener
- * the listener to be removed.
- * @see com.vaadin.terminal.Paintable#removeListener(Paintable.RepaintRequestListener)
- */
- public void removeListener(RepaintRequestListener listener);
-
- /**
- * Error messages are inmodifiable and thus listeners are not needed. This
- * method should be implemented as empty.
- *
- * @see com.vaadin.terminal.Paintable#requestRepaint()
- */
- public void requestRepaint();
+ @Deprecated
+ public void paint(PaintTarget target) throws PaintException;
}
package com.vaadin.terminal;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.Collections;
-import java.util.List;
-
-import com.vaadin.terminal.gwt.client.communication.SharedState;
import com.vaadin.terminal.gwt.server.AbstractApplicationServlet;
-import com.vaadin.terminal.gwt.server.ClientMethodInvocation;
/**
- * <code>SystemError</code> is a runtime exception caused by error in system.
- * The system error can be shown to the user as it implements
- * <code>ErrorMessage</code> interface, but contains technical information such
- * as stack trace and exception.
+ * <code>SystemError</code> is an error message for a problem caused by error in
+ * system, not the user application code. The system error can contain technical
+ * information such as stack trace and exception.
*
* SystemError does not support HTML in error messages or stack traces. If HTML
* messages are required, use {@link UserError} or a custom implementation of
* @since 3.0
*/
@SuppressWarnings("serial")
-public class SystemError extends RuntimeException implements ErrorMessage {
-
- /**
- * The cause of the system error. The cause is stored separately as JDK 1.3
- * does not support causes natively.
- */
- private Throwable cause = null;
+public class SystemError extends AbstractErrorMessage {
/**
* Constructor for SystemError with error message specified.
*/
public SystemError(String message) {
super(message);
+ setErrorLevel(ErrorLevel.SYSTEMERROR);
+ setMode(ContentMode.XHTML);
+ setMessage(getHtmlMessage());
}
/**
* the throwable causing the system error.
*/
public SystemError(String message, Throwable cause) {
- super(message);
- this.cause = cause;
+ this(message);
+ addCause(AbstractErrorMessage.getErrorMessageForException(cause));
}
/**
* the throwable causing the system error.
*/
public SystemError(Throwable cause) {
- this.cause = cause;
- }
-
- /**
- * @see com.vaadin.terminal.ErrorMessage#getErrorLevel()
- */
- public final ErrorLevel getErrorLevel() {
- return ErrorLevel.SYSTEMERROR;
- }
-
- /**
- * @see com.vaadin.terminal.Paintable#paint(com.vaadin.terminal.PaintTarget)
- */
- public void paint(PaintTarget target) throws PaintException {
-
- target.startTag("error");
- target.addAttribute("level", ErrorLevel.SYSTEMERROR.getText());
-
- String message = getHtmlMessage();
-
- target.addXMLSection("div", message,
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
-
- target.endTag("error");
-
- }
-
- public SharedState getState() {
- // TODO implement: move relevant parts from paint() to getState()
- return null;
- }
-
- public List<ClientMethodInvocation> retrievePendingRpcCalls() {
- return Collections.emptyList();
+ this(null, cause);
}
/**
* Note that this API may change in future versions.
*/
protected String getHtmlMessage() {
+ // TODO wrapping div with namespace? See the old code:
+ // target.addXMLSection("div", message,
+ // "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
+
StringBuilder sb = new StringBuilder();
- final String message = getLocalizedMessage();
- if (message != null) {
+ if (getMessage() != null) {
sb.append("<h2>");
- sb.append(AbstractApplicationServlet.safeEscapeForHtml(message));
+ sb.append(AbstractApplicationServlet
+ .safeEscapeForHtml(getMessage()));
sb.append("</h2>");
}
-
- // Paint the exception
- if (cause != null) {
- sb.append("<h3>Exception</h3>");
- final StringWriter buffer = new StringWriter();
- cause.printStackTrace(new PrintWriter(buffer));
- sb.append("<pre>");
- sb.append(AbstractApplicationServlet.safeEscapeForHtml(buffer
- .toString()));
- sb.append("</pre>");
- }
return sb.toString();
}
- /**
- * Gets cause for the error.
- *
- * @return the cause.
- * @see java.lang.Throwable#getCause()
- */
- @Override
- public Throwable getCause() {
- return cause;
- }
-
- /* Documented in super interface */
- public void addListener(RepaintRequestListener listener) {
- }
-
- /* Documented in super interface */
- public void removeListener(RepaintRequestListener listener) {
- }
-
- /* Documented in super interface */
- public void requestRepaint() {
- }
-
- /* Documented in super interface */
- public void requestRepaintRequests() {
- }
-
- public String getDebugId() {
- return null;
- }
-
- public void setDebugId(String id) {
- throw new UnsupportedOperationException(
- "Setting testing id for this Paintable is not implemented");
- }
-
}
package com.vaadin.terminal;
-import java.util.Collections;
-import java.util.List;
-
-import com.vaadin.terminal.gwt.client.communication.SharedState;
-import com.vaadin.terminal.gwt.server.AbstractApplicationServlet;
-import com.vaadin.terminal.gwt.server.ClientMethodInvocation;
-
/**
* <code>UserError</code> is a controlled error occurred in application. User
* errors are occur in normal usage of the application and guide the user.
* @since 3.0
*/
@SuppressWarnings("serial")
-public class UserError implements ErrorMessage {
-
- public enum ContentMode {
- /**
- * Content mode, where the error contains only plain text.
- */
- TEXT,
- /**
- * Content mode, where the error contains preformatted text.
- */
- PREFORMATTED,
- /**
- * Formatted content mode, where the contents is XML restricted to the
- * UIDL 1.0 formatting markups.
- */
- UIDL,
- /**
- * Content mode, where the error contains XHTML.
- */
- XHTML;
- }
+public class UserError extends AbstractErrorMessage {
/**
* @deprecated from 7.0, use {@link ContentMode#TEXT} instead  Â
@Deprecated
public static final ContentMode CONTENT_PREFORMATTED = ContentMode.PREFORMATTED;
- /**
- * @deprecated from 7.0, use {@link ContentMode#UIDL} instead  Â
- */
- @Deprecated
- public static final ContentMode CONTENT_UIDL = ContentMode.UIDL;
-
/**
* @deprecated from 7.0, use {@link ContentMode#XHTML} instead  Â
*/
@Deprecated
public static final ContentMode CONTENT_XHTML = ContentMode.XHTML;
- /**
- * Content mode.
- */
- private ContentMode mode = ContentMode.TEXT;
-
- /**
- * Message in content mode.
- */
- private final String msg;
-
- /**
- * Error level.
- */
- private ErrorLevel level = ErrorLevel.ERROR;
-
/**
* Creates a textual error message of level ERROR.
*
* the text of the error message.
*/
public UserError(String textErrorMessage) {
- msg = textErrorMessage;
+ super(textErrorMessage);
}
public UserError(String message, ContentMode contentMode,
ErrorLevel errorLevel) {
+ super(message);
if (contentMode == null) {
contentMode = ContentMode.TEXT;
}
if (errorLevel == null) {
errorLevel = ErrorLevel.ERROR;
}
- msg = message;
- mode = contentMode;
- level = errorLevel;
- }
-
- /* Documented in interface */
- public ErrorLevel getErrorLevel() {
- return level;
- }
-
- /* Documented in interface */
- public void addListener(RepaintRequestListener listener) {
- }
-
- /* Documented in interface */
- public void removeListener(RepaintRequestListener listener) {
- }
-
- /* Documented in interface */
- public void requestRepaint() {
- }
-
- /* Documented in interface */
- public void paint(PaintTarget target) throws PaintException {
-
- target.startTag("error");
- target.addAttribute("level", level.getText());
-
- // Paint the message
- switch (mode) {
- case TEXT:
- target.addText(AbstractApplicationServlet.safeEscapeForHtml(msg));
- break;
- case UIDL:
- target.addUIDL(msg);
- break;
- case PREFORMATTED:
- target.addText("<pre>"
- + AbstractApplicationServlet.safeEscapeForHtml(msg)
- + "</pre>");
- break;
- case XHTML:
- target.addText(msg);
- break;
- }
- target.endTag("error");
- }
-
- public SharedState getState() {
- // TODO implement: move relevant parts from paint() to getState()
- return null;
- }
-
- public List<ClientMethodInvocation> retrievePendingRpcCalls() {
- return Collections.emptyList();
- }
-
- /* Documented in interface */
- public void requestRepaintRequests() {
- }
-
- /* Documented in superclass */
- @Override
- public String toString() {
- return msg;
- }
-
- public String getDebugId() {
- return null;
- }
-
- public void setDebugId(String id) {
- throw new UnsupportedOperationException(
- "Setting testing id for this Paintable is not implemented");
+ setMode(contentMode);
+ setErrorLevel(errorLevel);
}
}
private int maxWidth = -1;
- protected static final String ATTRIBUTE_ICON = "icon";
+ protected static final String ATTRIBUTE_ICON = AbstractComponentConnector.ATTRIBUTE_ICON;
protected static final String ATTRIBUTE_CAPTION = "caption";
protected static final String ATTRIBUTE_DESCRIPTION = "description";
- protected static final String ATTRIBUTE_REQUIRED = "required";
- protected static final String ATTRIBUTE_ERROR = "error";
- protected static final String ATTRIBUTE_HIDEERRORS = "hideErrors";
+ protected static final String ATTRIBUTE_REQUIRED = AbstractComponentConnector.ATTRIBUTE_REQUIRED;
+ protected static final String ATTRIBUTE_ERROR = AbstractComponentConnector.ATTRIBUTE_ERROR;
+ protected static final String ATTRIBUTE_HIDEERRORS = AbstractComponentConnector.ATTRIBUTE_HIDEERRORS;
private enum InsertPosition {
ICON, CAPTION, REQUIRED, ERROR
getWidget().disableOnClick = getState().isDisableOnClick();
// handle error
- if (uidl.hasAttribute("error")) {
+ if (uidl.hasAttribute(ATTRIBUTE_ERROR)) {
if (getWidget().errorIndicatorElement == null) {
getWidget().errorIndicatorElement = DOM.createSpan();
getWidget().errorIndicatorElement
getWidget().blurHandlerRegistration = EventHelper.updateBlurHandler(
this, client, getWidget().blurHandlerRegistration);
- if (uidl.hasAttribute("error")) {
+ if (uidl.hasAttribute(ATTRIBUTE_ERROR)) {
if (getWidget().errorIndicatorElement == null) {
getWidget().errorIndicatorElement = DOM.createSpan();
getWidget().errorIndicatorElement.setInnerHTML(" ");
getWidget().removeStyleDependentName("nocaption");
}
- if (uidl.hasAttribute("error")) {
+ if (uidl.hasAttribute(ATTRIBUTE_ERROR)) {
final UIDL errorUidl = uidl.getErrors();
getWidget().errorMessage.updateFromUIDL(errorUidl);
getWidget().errorMessage.setVisible(true);
getWidget().captionElement.setInnerText(getState().getCaption());
// handle error
- if (uidl.hasAttribute("error")) {
+ if (uidl.hasAttribute(ATTRIBUTE_ERROR)) {
if (getWidget().errorIndicatorElement == null) {
getWidget().errorIndicatorElement = DOM.createDiv();
DOM.setElementProperty(getWidget().errorIndicatorElement,
getWidget().setText(getState().getCaption());
// handle error
- if (uidl.hasAttribute("error")) {
+ if (uidl.hasAttribute(ATTRIBUTE_ERROR)) {
if (getWidget().errorIndicatorElement == null) {
getWidget().errorIndicatorElement = DOM.createSpan();
getWidget().errorIndicatorElement
public void updateFromUIDL(UIDL uidl, ComponentConnector component) {
owner = component;
- if (uidl.hasAttribute("error")
+ if (uidl.hasAttribute(AbstractComponentConnector.ATTRIBUTE_ERROR)
&& !uidl.getBooleanAttribute(AbstractComponentConnector.ATTRIBUTE_HIDEERRORS)) {
if (errorIndicatorElement == null) {
errorIndicatorElement = DOM.createDiv();
}
void handleError(UIDL uidl) {
- if (uidl.hasAttribute("error")) {
+ if (uidl.hasAttribute(AbstractComponentConnector.ATTRIBUTE_ERROR)) {
if (errorIndicatorElement == null) {
errorIndicatorElement = DOM.createSpan();
DOM.setElementProperty(errorIndicatorElement, "className",
import com.vaadin.terminal.ThemeResource;
import com.vaadin.terminal.VariableOwner;
import com.vaadin.terminal.gwt.client.Connector;
+import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.ClientWidget;
import com.vaadin.ui.CustomLayout;
tag = new JsonTag(tagName);
- if ("error".equals(tagName)) {
+ if (AbstractComponentConnector.ATTRIBUTE_ERROR.equals(tagName)) {
errorsOpen++;
}
}
// simple hack which writes error uidl structure into attribute
- if ("error".equals(lastTag)) {
+ if (AbstractComponentConnector.ATTRIBUTE_ERROR.equals(lastTag)) {
if (errorsOpen == 1) {
- parent.addAttribute("\"error\":[\"error\",{}"
- + tag.getData() + "]");
+ parent.addAttribute("\""
+ + AbstractComponentConnector.ATTRIBUTE_ERROR
+ + "\":[\""
+ + AbstractComponentConnector.ATTRIBUTE_ERROR
+ + "\",{}" + tag.getData() + "]");
} else {
// sub error
parent.addData(tag.getJSON());
import com.vaadin.event.Action;
import com.vaadin.event.ShortcutAction;
import com.vaadin.event.ShortcutListener;
+import com.vaadin.terminal.AbstractErrorMessage;
import com.vaadin.terminal.CompositeErrorMessage;
import com.vaadin.terminal.ErrorMessage;
import com.vaadin.terminal.PaintException;
* the requiredError string. For these fields the exclamation mark will
* be hidden but the error must still be sent to the client.
*/
- ErrorMessage validationError = null;
+ Validator.InvalidValueException validationError = null;
if (isValidationVisible()) {
try {
validate();
}
// Throw combination of the error types
- return new CompositeErrorMessage(new ErrorMessage[] { superError,
- validationError, getCurrentBufferedSourceException() });
+ return new CompositeErrorMessage(
+ new ErrorMessage[] {
+ superError,
+ AbstractErrorMessage
+ .getErrorMessageForException(validationError),
+ AbstractErrorMessage
+ .getErrorMessageForException(getCurrentBufferedSourceException()) });
}
import com.vaadin.event.Action.Handler;
import com.vaadin.event.Action.ShortcutNotifier;
import com.vaadin.event.ActionManager;
+import com.vaadin.terminal.AbstractErrorMessage;
import com.vaadin.terminal.CompositeErrorMessage;
import com.vaadin.terminal.ErrorMessage;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
+import com.vaadin.terminal.UserError;
import com.vaadin.terminal.gwt.client.ui.FormConnector;
/**
if (validationError != null) {
// Show caption as error for fields with empty errors
if ("".equals(validationError.toString())) {
- validationError = new Validator.InvalidValueException(
- field.getCaption());
+ validationError = new UserError(field.getCaption());
}
break;
} else if (f instanceof Field && !((Field<?>) f).isValid()) {
// Something is wrong with the field, but no proper
// error is given. Generate one.
- validationError = new Validator.InvalidValueException(
- field.getCaption());
+ validationError = new UserError(field.getCaption());
break;
}
}
}
// Throw combination of the error types
- return new CompositeErrorMessage(new ErrorMessage[] {
- getComponentError(), validationError,
- currentBufferedSourceException });
+ return new CompositeErrorMessage(
+ new ErrorMessage[] {
+ getComponentError(),
+ validationError,
+ AbstractErrorMessage
+ .getErrorMessageForException(currentBufferedSourceException) });
}
/**
package com.vaadin.tests.components.checkbox;
import com.vaadin.data.Validator.InvalidValueException;
+import com.vaadin.terminal.AbstractErrorMessage;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
try {
checkbox.validate();
} catch (InvalidValueException e) {
- checkbox.setComponentError(e);
+ checkbox.setComponentError(AbstractErrorMessage
+ .getErrorMessageForException(e));
}
try {
requiredCheckbox.validate();
} catch (InvalidValueException e) {
- requiredCheckbox.setComponentError(e);
+ requiredCheckbox.setComponentError(AbstractErrorMessage
+ .getErrorMessageForException(e));
}
valueLabel.setValue("Checkbox: " + checkbox.getValue()
+ "; Required checkbox: " + requiredCheckbox.getValue());
import com.vaadin.data.Item;
import com.vaadin.data.Validator;
import com.vaadin.data.util.BeanItem;
+import com.vaadin.terminal.AbstractErrorMessage;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
"Ipsum lipsum laarum lop... ");
for (Object propIDs : getItemDataSource().getItemPropertyIds()) {
- ((TextField) getField(propIDs)).setComponentError(ive);
+ ((TextField) getField(propIDs))
+ .setComponentError(AbstractErrorMessage
+ .getErrorMessageForException(ive));
}