Example usage for org.apache.wicket.validation IValidationError getErrorMessage

List of usage examples for org.apache.wicket.validation IValidationError getErrorMessage

Introduction

In this page you can find the example usage for org.apache.wicket.validation IValidationError getErrorMessage.

Prototype

Serializable getErrorMessage(IErrorMessageSource messageSource);

Source Link

Document

Retrieves the error message (usually user-facing).

Usage

From source file:com.premiumminds.wicket.crudifier.form.elements.CollectionControlGroup.java

License:Open Source License

@SuppressWarnings({ "unchecked", "serial" })
public CollectionControlGroup(String id, IModel<T> model) {
    super(id, model);

    IModel<List<T>> modelList = new LoadableDetachableModel<List<T>>() {
        private static final long serialVersionUID = 3674039468142186197L;

        @Override/*from w w  w.j a va2  s.  c  o m*/
        protected List<T> load() {
            return (List<T>) entityProvider.load();
        }
    };

    multiChoice = new ListMultipleChoice("input", getModel(), modelList, new ChoiceRenderer()) {
        @Override
        public void error(IValidationError error) {
            MessageSource source = new MessageSource();
            Serializable message = error.getErrorMessage(source);

            super.error(message);
        }
    };
}

From source file:com.premiumminds.wicket.crudifier.form.elements.DateControlGroup.java

License:Open Source License

public DateControlGroup(String id, IModel<Date> model) {
    super(id, model);

    BootstrapDatepicker datepicker = new BootstrapDatepicker("datepicker") {
        private static final long serialVersionUID = -1294334224980199521L;

        @Override/*from  w  w w  .  jav a 2 s  .c  om*/
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (isEnabledInHierarchy())
                tag.append("class", "input-append", " ");
        }
    };

    dateField = new DateTextField("input", getModel()) {
        private static final long serialVersionUID = 4925601760084153117L;

        @Override
        public void error(IValidationError error) {
            MessageSource source = new MessageSource();
            Serializable message = error.getErrorMessage(source);

            super.error(message);
        }
    };

    datepicker.add(dateField);
    datepicker.add(new WebMarkupContainer("icon") {
        private static final long serialVersionUID = -4412622222987841668L;

        @Override
        protected void onConfigure() {
            super.onConfigure();
            //don't display icon if it is disabled
            setVisible(dateField.isEnabledInHierarchy());
        }
    });
    add(new BootstrapControlGroupFeedback("controlGroup").add(datepicker));

}

From source file:com.premiumminds.wicket.crudifier.form.elements.JodaInstantControlGroup.java

License:Open Source License

public JodaInstantControlGroup(String id, IModel<DateTime> model) {
    super(id, model);

    BootstrapJodaDatepicker<DateTime> datepicker = new BootstrapJodaDatepicker<DateTime>("datepicker") {
        private static final long serialVersionUID = -1294334224980199521L;

        @Override/*from  w w  w  . j  a v a  2  s .c  om*/
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (isEnabledInHierarchy())
                tag.append("class", "input-append", " ");
        }
    };

    dateField = new JodaInstantTextField<DateTime>("input", getModel(), DateTime.class) {
        private static final long serialVersionUID = 4925601760084153117L;

        @Override
        public void error(IValidationError error) {
            MessageSource source = new MessageSource();
            Serializable message = error.getErrorMessage(source);

            super.error(message);
        }
    };

    datepicker.add(dateField);
    datepicker.add(new WebMarkupContainer("icon") {
        private static final long serialVersionUID = -4412622222987841668L;

        @Override
        protected void onConfigure() {
            super.onConfigure();
            //don't display icon if it is disabled
            setVisible(dateField.isEnabledInHierarchy());
        }
    });
    add(new BootstrapControlGroupFeedback("controlGroup").add(datepicker));

}

From source file:com.premiumminds.wicket.crudifier.form.elements.ObjectChoiceControlGroup.java

License:Open Source License

@SuppressWarnings("serial")
public ObjectChoiceControlGroup(String id, IModel<T> model) {
    super(id, model);

    IModel<List<? extends T>> modelList = new LoadableDetachableModel<List<? extends T>>() {
        private static final long serialVersionUID = -3995535290067544541L;

        @Override//from  www . j a  va 2 s  . c  o  m
        protected List<T> load() {
            if (entityProvider == null)
                throw new RuntimeException("no entity provider for '" + getPropertyName() + "'");
            return (List<T>) entityProvider.load();
        }

    };

    dropDown = new DropDownChoice<T>("input", getModel(), modelList) {
        @Override
        public void error(IValidationError error) {
            MessageSource source = new MessageSource();
            Serializable message = error.getErrorMessage(source);

            super.error(message);
        }
    };
}

From source file:com.premiumminds.wicket.crudifier.form.elements.TextFieldControlGroup.java

License:Open Source License

public TextFieldControlGroup(String id, IModel<T> model) {
    super(id, model);

    textField = new TextField<T>("input", getModel()) {
        private static final long serialVersionUID = 4925601760084153117L;

        @Override//from  w w  w  . ja  v  a 2s.  c o  m
        public void error(IValidationError error) {
            MessageSource source = new MessageSource();
            Serializable message = error.getErrorMessage(source);

            super.error(message);
        }
    };
}

From source file:org.wicketstuff.rest.resource.AbstractRestResource.java

License:Apache License

/**
 * Handle the different steps (authorization, validation, etc...) involved in method execution.
 *
 * @param attributesWrapper//from   w  w  w  .  j  a  va 2  s.c o  m
 *            wrapper for the current Attributes
 * @param mappedMethod
 *            the mapped method to execute
 */
private void handleMethodExecution(AttributesWrapper attributesWrapper,
        ScoreMethodAndExtractPathVars mappedMethod) {
    WebResponse response = attributesWrapper.getWebResponse();
    HttpMethod httpMethod = attributesWrapper.getHttpMethod();
    Attributes attributes = attributesWrapper.getOriginalAttributes();
    MethodMappingInfo methodInfo = mappedMethod.getMethodInfo();
    String outputFormat = methodInfo.getOutputFormat();

    // 1-check if user is authorized to invoke the method
    if (!isUserAuthorized(methodInfo.getRoles())) {
        response.write(USER_IS_NOT_ALLOWED);
        response.setStatus(401);
        return;
    }

    // 2-extract method parameters
    List<?> parametersValues = extractMethodParameters(mappedMethod, attributesWrapper);

    if (parametersValues == null) {
        noSuitableMethodFound(response, httpMethod);
        return;
    }

    // 3-validate method parameters
    List<IValidationError> validationErrors = validateMethodParameters(methodInfo, parametersValues);

    if (validationErrors.size() > 0) {
        IValidationError error = validationErrors.get(0);
        Serializable message = error.getErrorMessage(bundleResolver);

        webSerialDeserial.objectToResponse(message, response, outputFormat);
        response.setStatus(400);

        return;
    }

    // 4-invoke method triggering the before-after hooks
    onBeforeMethodInvoked(methodInfo, attributes);
    Object result = invokeMappedMethod(methodInfo.getMethod(), parametersValues, response);
    onAfterMethodInvoked(methodInfo, attributes, result);

    // 5-if the invoked method returns a value, it is written to response
    if (result != null) {
        objectToResponse(result, response, outputFormat);
    }
}