    001// Licensed under the Apache License, Version 2.0 (the "License");
    002// you may not use this file except in compliance with the License.
    003// You may obtain a copy of the License at
    004//
    005// http://www.apache.org/licenses/LICENSE-2.0
    006//
    007// Unless required by applicable law or agreed to in writing, software
    008// distributed under the License is distributed on an "AS IS" BASIS,
    009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    010// See the License for the specific language governing permissions and
    011// limitations under the License.
    012
    013package org.apache.tapestry5.annotations;
    014
    015import static java.lang.annotation.ElementType.PARAMETER;
    016import static java.lang.annotation.RetentionPolicy.RUNTIME;
    017import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.PAGE;
    018
    019import java.lang.annotation.Documented;
    020import java.lang.annotation.Retention;
    021import java.lang.annotation.Target;
    022
    023import org.apache.tapestry5.commons.services.TypeCoercer;
    024import org.apache.tapestry5.http.services.HttpRequestBodyConverter;
    025import org.apache.tapestry5.internal.transform.OnEventWorker;
    026import org.apache.tapestry5.ioc.annotations.UseWith;
    027
    028/**
    029 * Annotation that may be placed on parameters of event handler methods,
    030 * usually in page classes.
    031 * Annotated parameters will be extracted fro the request body and converted
    032 * to the parameter type using {@linkplain HttpRequestBodyConverter}, which uses
    033 * {@linkplain TypeCoercer} as a fallback.
    034 * An event handler method having more than one {@linkplain RequestBody}
    035 * parameter is considered an error.
    036 *
    037 * @since 5.8.0
    038 * @see OnEventWorker
    039 */
    040@Target(
    041{ PARAMETER })
    042@Retention(RUNTIME)
    043@Documented
    044@UseWith(
    045{ PAGE })
    046public @interface RequestBody
    047{
    048    /**
    049     * If false (the default), then an exception is thrown when the request body is empty (i.e. zero bytes).
    050     * If true, then empty bodies are allowed and the parameter will receive a null value.
    051     */
    052    boolean allowEmpty() default false;
    053}