Search in sources :

Example 96 with Component

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

the class UploadTest method process_submission_calls_validator.

@SuppressWarnings("unchecked")
@Test
public void process_submission_calls_validator() throws Exception {
    MultipartDecoder decoder = mockMultipartDecoder();
    UploadedFile uploadedFile = mockUploadedFile();
    FieldValidator<Object> validate = mockFieldValidator();
    ComponentResources resources = mockComponentResources();
    FieldValidationSupport support = mockFieldValidationSupport();
    Upload component = new Upload(null, validate, decoder, null, resources, support);
    expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
    expect(uploadedFile.getFileName()).andReturn("test").atLeastOnce();
    support.validate(uploadedFile, resources, validate);
    replay();
    component.processSubmission("test");
    verify();
}
Also used : UploadedFile(org.apache.tapestry5.upload.services.UploadedFile) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) Test(org.testng.annotations.Test)

Example 97 with Component

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

the class Form method preallocateNames.

private void preallocateNames(IdAllocator idAllocator) {
    for (String name : formControlNameManager.getReservedNames()) {
        idAllocator.allocateId(name);
        // See https://issues.apache.org/jira/browse/TAP5-1632
        javascriptSupport.allocateClientId(name);
    }
    Component activePage = componentSource.getActivePage();
    if (activePage == null)
        return;
    ComponentResources activePageResources = activePage.getComponentResources();
    try {
        activePageResources.triggerEvent(EventConstants.PREALLOCATE_FORM_CONTROL_NAMES, new Object[] { idAllocator }, null);
    } catch (RuntimeException ex) {
        logger.error(String.format("Unable to obtain form control names to preallocate: %s", ExceptionUtils.toMessage(ex)), ex);
    }
}
Also used : Component(org.apache.tapestry5.runtime.Component)

Example 98 with Component

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

the class Form method executeStoredActions.

/**
 * Pulls the stored actions out of the request, converts them from MIME
 * stream back to object stream and then
 * objects, and executes them.
 */
private void executeStoredActions(boolean forFormCancel) {
    String[] values = request.getParameters(FORM_DATA);
    if (!request.getMethod().equals("POST") || values == null)
        throw new RuntimeException(messages.format("core-invalid-form-request", FORM_DATA));
    for (String clientEncodedActions : values) {
        if (InternalUtils.isBlank(clientEncodedActions))
            continue;
        logger.debug("Processing actions: {}", clientEncodedActions);
        ObjectInputStream ois = null;
        Component component = null;
        try {
            ois = clientDataEncoder.decodeClientData(clientEncodedActions);
            while (!eventCallback.isAborted()) {
                String componentId = ois.readUTF();
                boolean cancelAction = ois.readBoolean();
                ComponentAction action = (ComponentAction) ois.readObject();
                // based on whether the form was submitted or cancelled.
                if (forFormCancel != cancelAction) {
                    continue;
                }
                component = source.getComponent(componentId);
                logger.debug("Processing: {} {}", componentId, action);
                action.execute(component);
                component = null;
            }
        } catch (EOFException ex) {
        // Expected
        } catch (Exception ex) {
            Location location = component == null ? null : component.getComponentResources().getLocation();
            throw new TapestryException(ex.getMessage(), location, ex);
        } finally {
            InternalUtils.close(ois);
        }
    }
}
Also used : EOFException(java.io.EOFException) Component(org.apache.tapestry5.runtime.Component) IOException(java.io.IOException) EOFException(java.io.EOFException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ObjectInputStream(java.io.ObjectInputStream) Location(org.apache.tapestry5.commons.Location)

Example 99 with Component

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

the class ProgressiveDisplay method beginRender.

Block beginRender(MarkupWriter writer) {
    String clientId = jsSupport.allocateClientId(resources);
    String elementName = resources.getElementName("div");
    writer.element(elementName, "id", clientId, "data-container-type", "zone");
    resources.renderInformalParameters(writer);
    Link link = resources.createEventLink(EventConstants.ACTION, context);
    jsSupport.require("t5/core/zone").invoke("deferredZoneUpdate").with(clientId, link.toURI());
    // of the component.
    return initial;
}
Also used : Link(org.apache.tapestry5.http.Link)

Example 100 with Component

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

the class DateField method beginRender.

void beginRender(MarkupWriter writer) {
    String value = validationTracker.getInput(this);
    if (value == null) {
        value = formatCurrentValue();
    }
    String clientId = getClientId();
    writer.element("div", "data-component-type", "core/DateField", "data-parse-url", resources.createEventLink("parse").toString(), "data-format-url", resources.createEventLink("format").toString());
    if (!hideTextField) {
        writer.attributes("class", "input-group");
    }
    Element field = writer.element("input", "type", type, "class", cssClass, "name", getControlName(), "id", clientId, "value", value);
    if (hideTextField) {
        field.attribute("class", "hide");
    }
    writeDisabled(writer);
    putPropertyNameIntoBeanValidationContext("value");
    validate.render(writer);
    removePropertyNameFromBeanValidationContext();
    resources.renderInformalParameters(writer);
    decorateInsideField();
    // input
    writer.end();
    if (!hideTextField) {
        writer.element("span", "class", "input-group-btn");
    }
    writer.element("button", "type", "button", "class", "btn btn-default", "alt", "[Show]");
    writer.element("span", "class", "glyphicon glyphicon-calendar");
    // span
    writer.end();
    // button
    writer.end();
    if (!hideTextField) {
        // span.input-group-btn
        writer.end();
    }
    // outer div
    writer.end();
}
Also used : Element(org.apache.tapestry5.dom.Element)

Aggregations

Test (org.testng.annotations.Test)68 Component (org.apache.tapestry5.runtime.Component)43 ComponentResources (org.apache.tapestry5.ComponentResources)41 MarkupWriter (org.apache.tapestry5.MarkupWriter)18 ComponentModel (org.apache.tapestry5.model.ComponentModel)18 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)17 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)16 Binding (org.apache.tapestry5.Binding)14 Location (org.apache.tapestry5.commons.Location)14 Instantiator (org.apache.tapestry5.internal.services.Instantiator)12 Page (org.apache.tapestry5.internal.structure.Page)12 Messages (org.apache.tapestry5.commons.Messages)8 Resource (org.apache.tapestry5.commons.Resource)8 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)7 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)7 BindingFactory (org.apache.tapestry5.services.BindingFactory)7 Logger (org.slf4j.Logger)7 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)6 BindingSource (org.apache.tapestry5.services.BindingSource)6 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)5