Search in sources :

Example 11 with Component

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

the class UploadTest method process_submission_ignores_null_value.

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

Example 12 with Component

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

the class UploadTest method validation_decorator_invoked_inside_begin_render.

@Test
public void validation_decorator_invoked_inside_begin_render() throws Exception {
    getMocksControl().checkOrder(true);
    ComponentResources resources = mockComponentResources();
    Upload component = new Upload(null, null, null, null, resources, null);
    MarkupWriter writer = createMarkupWriter();
    writer.element("form");
    FieldValidator validator = mockFieldValidator();
    Request request = mockRequest();
    FormSupport formSupport = mockFormSupport();
    formSupport.setEncodingType(Upload.MULTIPART_ENCTYPE);
    component.injectFormSupport(formSupport).injectRequest(request);
    ValidationDecorator decorator = mockValidationDecorator();
    component.injectDecorator(decorator).injectFieldValidator(validator);
    validator.render(writer);
    resources.renderInformalParameters(writer);
    decorator.insideField(component);
    train_isXHR(request, false);
    replay();
    component.beginRender(writer);
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) FormSupport(org.apache.tapestry5.services.FormSupport) Test(org.testng.annotations.Test)

Example 13 with Component

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

the class UploadTest method process_submission_tracks_validator_errors.

@SuppressWarnings({ "unchecked", "ThrowableInstanceNeverThrown" })
@Test
public void process_submission_tracks_validator_errors() throws Exception {
    MultipartDecoder decoder = mockMultipartDecoder();
    UploadedFile uploadedFile = mockUploadedFile();
    FieldValidator<Object> validate = mockFieldValidator();
    ValidationTracker tracker = mockValidationTracker();
    ComponentResources resources = mockComponentResources();
    FieldValidationSupport support = mockFieldValidationSupport();
    Upload component = new Upload(null, validate, decoder, tracker, resources, support);
    expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
    expect(uploadedFile.getFileName()).andReturn("test").atLeastOnce();
    support.validate(uploadedFile, resources, validate);
    expectLastCall().andThrow(new ValidationException("an error"));
    tracker.recordError(component, "an error");
    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 14 with Component

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

the class BindingSourceImpl method newBinding.

public Binding newBinding(String description, ComponentResources container, ComponentResources component, String defaultPrefix, String expression, Location location) {
    assert InternalUtils.isNonBlank(description);
    assert container != null;
    assert InternalUtils.isNonBlank(defaultPrefix);
    assert component != null;
    // TAP5-845: The expression may be the empty string. This is ok, if it's compatible with
    // the default prefix (the empty string is not a valid property expression, but is valid
    // as a literal string, perhaps as an informal parameter).
    // Location might be null
    String subexpression = expression;
    int colonx = expression.indexOf(':');
    BindingFactory factory = null;
    if (colonx > 0) {
        String prefix = expression.substring(0, colonx);
        factory = factories.get(prefix);
        if (factory != null)
            subexpression = expression.substring(colonx + 1);
    }
    if (factory == null)
        factory = factories.get(defaultPrefix);
    try {
        return factory.newBinding(interner.intern(description), container, component, subexpression, location);
    } catch (Exception ex) {
        throw new TapestryException(String.format("Could not convert '%s' into a component parameter binding: %s", expression, ExceptionUtils.toMessage(ex)), location, ex);
    }
}
Also used : TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) BindingFactory(org.apache.tapestry5.services.BindingFactory)

Example 15 with Component

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

the class AjaxComponentInstanceEventResultProcessor method processResultValue.

public void processResultValue(Component value) throws IOException {
    ComponentResources resources = value.getComponentResources();
    boolean isPage = value == resources.getPage();
    String pageName = resources.getPageName();
    if (isPage) {
        // This will ultimately send a JSON response to redirect to the page
        masterProcessor.processResultValue(pageName);
        return;
    }
    // Otherwise, a component within a page. Components are transformed to implement RenderCommand, but if we just
    // pass the component itself to the master processor, we'll get in a loop, so we instead
    // pass the ComponentPageElement (which implements RenderCommand as well).
    Page page = cache.get(pageName);
    String nestedId = resources.getNestedId();
    RenderCommand command = page.getComponentElementByNestedId(nestedId);
    masterProcessor.processResultValue(command);
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand) Page(org.apache.tapestry5.internal.structure.Page) ComponentResources(org.apache.tapestry5.ComponentResources)

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