use of org.apache.tapestry5.dom.Element in project tapestry-5 by apache.
the class UploadTest method begin_render_writes_input_tag.
@Test
public void begin_render_writes_input_tag() throws Exception {
MarkupWriter writer = createMarkupWriter();
writer.element("form");
FormSupport formSupport = mockFormSupport();
ComponentResources resources = mockComponentResources();
FieldValidator validator = mockFieldValidator();
Request request = mockRequest();
train_isXHR(request, false);
formSupport.setEncodingType(Upload.MULTIPART_ENCTYPE);
validator.render(writer);
resources.renderInformalParameters(writer);
replay();
Upload component = new Upload(null, null, null, null, resources, null);
component.injectDecorator(new BaseValidationDecorator()).injectFormSupport(formSupport).injectFieldValidator(validator).injectRequest(request);
component.beginRender(writer);
Element element = writer.getElement();
assertNotNull(element);
assertEquals(element.getName(), "input");
assertEquals(element.getAttribute("type"), "file");
// assertEquals(element.getAttribute("name"),null);
// assertEquals(element.getAttribute("id"),null);
verify();
}
use of org.apache.tapestry5.dom.Element in project tapestry-5 by apache.
the class DynamicTemplateSaxParser method element.
private DynamicTemplateElement element() {
String elementURI = tokenStream.getNamespaceURI();
String elementName = tokenStream.getLocalName();
String blockId = null;
int count = tokenStream.getAttributeCount();
List<DynamicTemplateAttribute> attributes = CollectionFactory.newList();
Location location = getLocation();
for (int i = 0; i < count; i++) {
QName qname = tokenStream.getAttributeName(i);
// The name will be blank for an xmlns: attribute
String localName = qname.getLocalPart();
if (InternalUtils.isBlank(localName))
continue;
String uri = qname.getNamespaceURI();
String value = tokenStream.getAttributeValue(i);
if (localName.equals("id")) {
Matcher matcher = PARAM_ID_PATTERN.matcher(value);
if (matcher.matches()) {
blockId = matcher.group(1);
continue;
}
}
Mapper<DynamicDelegate, String> attributeValueExtractor = createCompositeExtractorFromText(value, location);
attributes.add(new DynamicTemplateAttribute(uri, localName, attributeValueExtractor));
}
if (blockId != null)
return block(blockId);
List<DynamicTemplateElement> body = CollectionFactory.newList();
boolean atEnd = false;
while (!atEnd) {
switch(tokenStream.next()) {
case START_ELEMENT:
// Recurse into this new element
body.add(element());
break;
case END_ELEMENT:
body.add(END);
atEnd = true;
break;
default:
addTextContent(body);
}
}
return createElementWriterElement(elementURI, elementName, attributes, body);
}
use of org.apache.tapestry5.dom.Element in project tapestry-5 by apache.
the class PageLoaderImpl method parameter.
private void parameter(AssemblerContext context) {
final ParameterToken token = context.next(ParameterToken.class);
context.add(new PageAssemblyAction() {
public void execute(PageAssembly pageAssembly) {
String parameterName = token.name;
ComponentPageElement element = pageAssembly.createdElement.peek();
Location location = token.getLocation();
BlockImpl block = new BlockImpl(location, interner.format("Parameter %s of %s", parameterName, element.getCompleteId()));
Binding binding = new LiteralBinding(location, "block parameter " + parameterName, block);
EmbeddedComponentAssembler embeddedAssembler = pageAssembly.embeddedAssembler.peek();
ParameterBinder binder = embeddedAssembler.createParameterBinder(parameterName);
if (binder == null) {
throw new UnknownValueException(String.format("Component %s does not include a formal parameter '%s' (and does not support informal parameters).", element.getCompleteId(), parameterName), location, null, new AvailableValues("Formal parameters", embeddedAssembler.getFormalParameterNames()));
}
binder.bind(pageAssembly.createdElement.peek(), binding);
pageAssembly.bodyElement.push(block);
}
});
consumeToEndElementAndPopBodyElement(context);
}
use of org.apache.tapestry5.dom.Element in project tapestry-5 by apache.
the class PageActivationContextCollectorImplTest method page_with_no_context.
@Test
public void page_with_no_context() {
String pageName = "mypage";
ComponentModel model = mockComponentModel();
ComponentModelSource modelSource = mockComponentModelSource();
RequestPageCache pageCache = mockRequestPageCache();
Page page = mockPage();
ComponentPageElement element = mockComponentPageElement();
expect(modelSource.getPageModel(pageName)).andReturn(model);
expect(model.handlesEvent(EventConstants.PASSIVATE)).andReturn(true);
train_get(pageCache, pageName, page);
train_getRootElement(page, element);
expect(element.triggerEvent(EasyMock.eq(EventConstants.PASSIVATE), (Object[]) EasyMock.isNull(), EasyMock.isA(ComponentEventCallback.class))).andReturn(false);
replay();
PageActivationContextCollector collector = new PageActivationContextCollectorImpl(coercer, pageCache, modelSource);
Object[] actual = collector.collectPageActivationContext(pageName);
assertEquals(actual.length, 0);
}
use of org.apache.tapestry5.dom.Element in project tapestry-5 by apache.
the class ComponentEventRequestHandlerImpl method handle.
public void handle(ComponentEventRequestParameters parameters) throws IOException {
Page activePage = cache.get(parameters.getActivePageName());
if (pageActivator.activatePage(activePage.getRootElement().getComponentResources(), parameters.getPageActivationContext(), resultProcessor)) {
return;
}
Page containerPage = cache.get(parameters.getContainingPageName());
TrackableComponentEventCallback callback = new ComponentResultProcessorWrapper(resultProcessor);
environment.push(ComponentEventResultProcessor.class, resultProcessor);
environment.push(TrackableComponentEventCallback.class, callback);
ComponentPageElement element = containerPage.getComponentElementByNestedId(parameters.getNestedComponentId());
boolean handled = element.triggerContextEvent(parameters.getEventType(), parameters.getEventContext(), callback);
if (!handled) {
throw new TapestryException(String.format("Request event '%s' (on component %s) was not handled; you must provide a matching event handler method in the component or in one of its containers.", parameters.getEventType(), element.getCompleteId()), element, null);
}
environment.pop(TrackableComponentEventCallback.class);
environment.pop(ComponentEventResultProcessor.class);
if (callback.isAborted()) {
callback.rethrow();
return;
}
if (!response.isCommitted()) {
resultProcessor.processResultValue(activePage.getName());
}
}
Aggregations