Search in sources :

Example 1 with RequestParameter

use of org.apache.tapestry5.annotations.RequestParameter in project tapestry-5 by apache.

the class DefaultOpenApiTypeDescriber method describe.

@Override
public void describe(JSONObject description, Parameter parameter) {
    describeType(description, parameter.getType());
    // According to the OpenAPI 3 documentation, path parameters are always required.
    final RequestParameter requestParameter = parameter.getAnnotation(RequestParameter.class);
    if (requestParameter == null || requestParameter != null && !requestParameter.allowBlank()) {
        description.put("required", true);
    }
}
Also used : RequestParameter(org.apache.tapestry5.annotations.RequestParameter)

Example 2 with RequestParameter

use of org.apache.tapestry5.annotations.RequestParameter in project tapestry-5 by apache.

the class Select method onChange.

Object onChange(final EventContext context, @RequestParameter(value = "t:selectvalue", allowBlank = true) final String selectValue) throws ValidationException {
    final Object newValue = toValue(selectValue);
    CaptureResultCallback<Object> callback = new CaptureResultCallback<Object>();
    EventContext newContext = new AbstractEventContext() {

        @Override
        public int getCount() {
            return context.getCount() + 1;
        }

        @Override
        public <T> T get(Class<T> desiredType, int index) {
            if (index == 0) {
                return typeCoercer.coerce(newValue, desiredType);
            }
            return context.get(desiredType, index - 1);
        }
    };
    this.resources.triggerContextEvent(EventConstants.VALUE_CHANGED, newContext, callback);
    this.value = newValue;
    return callback.getResult();
}
Also used : AbstractEventContext(org.apache.tapestry5.internal.AbstractEventContext) CaptureResultCallback(org.apache.tapestry5.internal.util.CaptureResultCallback) AbstractEventContext(org.apache.tapestry5.internal.AbstractEventContext)

Example 3 with RequestParameter

use of org.apache.tapestry5.annotations.RequestParameter in project tapestry-5 by apache.

the class Autocomplete method onAutocomplete.

Object onAutocomplete(final EventContext context, @RequestParameter("t:input") final String input) {
    final Holder<List> matchesHolder = Holder.create();
    // Default it to an empty list.
    matchesHolder.put(Collections.emptyList());
    ComponentEventCallback callback = new ComponentEventCallback() {

        public boolean handleResult(Object result) {
            List matches = coercer.coerce(result, List.class);
            matchesHolder.put(matches);
            return true;
        }
    };
    EventContext newContext = new AbstractEventContext() {

        @Override
        public int getCount() {
            return context.getCount() + 1;
        }

        @Override
        public <T> T get(Class<T> desiredType, int index) {
            if (index == 0) {
                return coercer.coerce(input, desiredType);
            }
            return context.get(desiredType, index - 1);
        }
    };
    resources.triggerContextEvent(EventConstants.PROVIDE_COMPLETIONS, newContext, callback);
    JSONObject reply = new JSONObject();
    reply.put("matches", JSONArray.from(matchesHolder.get()));
    // A JSONObject response is always preferred, as that triggers the whole partial page render pipeline.
    return reply;
}
Also used : AbstractEventContext(org.apache.tapestry5.internal.AbstractEventContext) AbstractEventContext(org.apache.tapestry5.internal.AbstractEventContext) JSONObject(org.apache.tapestry5.json.JSONObject) List(java.util.List) JSONObject(org.apache.tapestry5.json.JSONObject)

Example 4 with RequestParameter

use of org.apache.tapestry5.annotations.RequestParameter in project tapestry-5 by apache.

the class DateField method onFormat.

/**
 * Ajax event handler, used after the client-side popup completes. The client sends the date, formatted as
 * milliseconds since the epoch, to the server, which reformats it according to the server side format and returns
 * the result.
 * @throws ParseException
 */
JSONObject onFormat(@RequestParameter(INPUT_PARAMETER) String input) throws ParseException {
    JSONObject response = new JSONObject();
    try {
        Date date = new SimpleDateFormat("yyyy-MM-dd").parse(input);
        response.put(RESULT, format.format(date));
    } catch (NumberFormatException ex) {
        response.put(ERROR, ex.getMessage());
    }
    return response;
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 5 with RequestParameter

use of org.apache.tapestry5.annotations.RequestParameter in project tapestry-5 by apache.

the class DateField method onParse.

/**
 * Ajax event handler, used when initiating the popup. The client sends the input value form the field to the server
 * to parse it according to the server-side format. The response contains a "result" key of the formatted date in a
 * format acceptable to the JavaScript Date() constructor. Alternately, an "error" key indicates the the input was
 * not formatted correct.
 */
JSONObject onParse(@RequestParameter(INPUT_PARAMETER) String input) {
    JSONObject response = new JSONObject();
    try {
        Date date = format.parse(input);
        response.put(RESULT, new SimpleDateFormat("yyyy-MM-dd").format(date));
    } catch (ParseException ex) {
        response.put(ERROR, ex.getMessage());
    }
    return response;
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

JSONObject (org.apache.tapestry5.json.JSONObject)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 RequestParameter (org.apache.tapestry5.annotations.RequestParameter)2 AbstractEventContext (org.apache.tapestry5.internal.AbstractEventContext)2 ParseException (java.text.ParseException)1 List (java.util.List)1 ActivationContextParameter (org.apache.tapestry5.annotations.ActivationContextParameter)1 CaptureResultCallback (org.apache.tapestry5.internal.util.CaptureResultCallback)1