use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class AbstractConditional method beginRender.
/**
* Returns null if the {@link #test()} is true, which allows normal rendering (of the body). If the test parameter
* is false, returns the else parameter (this may also be null).
*/
Object beginRender(MarkupWriter writer) {
boolean enabled = test();
Block toRender = enabled ? (thenBlock == null ? resources.getBody() : thenBlock) : elseBlock;
String elementName = resources.getElementName();
if (enabled && elementName != null) {
renderTag = true;
writer.element(elementName);
resources.renderInformalParameters(writer);
}
return toRender;
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class AbstractPropertyOutput method renderPropertyValue.
/**
* Invoked from subclasses to do the rendering. The subclass controls the naming convention for locating an
* overriding Block parameter (it is the name of the property possibly suffixed with a value).
* @param writer a MarkupWriter
* @param overrideBlockId the override block id
* @return a Block
*/
protected Object renderPropertyValue(MarkupWriter writer, String overrideBlockId) {
Block override = overrides.getOverrideBlock(overrideBlockId);
if (override != null)
return override;
String datatype = model.getDataType();
if (beanBlockSource.hasDisplayBlock(datatype)) {
PropertyOutputContext context = new PropertyOutputContext() {
public Messages getMessages() {
return overrides.getOverrideMessages();
}
public Object getPropertyValue() {
return readPropertyForObject();
}
public String getPropertyId() {
return model.getId();
}
public String getPropertyName() {
return model.getPropertyName();
}
};
environment.push(PropertyOutputContext.class, context);
mustPopEnvironment = true;
return beanBlockSource.getDisplayBlock(datatype);
}
Object value = readPropertyForObject();
String text = value == null ? "" : value.toString();
if (InternalUtils.isNonBlank(text)) {
writer.write(text);
}
return false;
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class BeanBlockSourceImplTest method conflicting_bean_block_overrides.
@Test
public // TAP5-2506
void conflicting_bean_block_overrides() {
RequestPageCache cache = mockRequestPageCache();
Collection<BeanBlockContribution> configuration = CollectionFactory.newList();
configuration.add(new DisplayBlockContribution("foo", "page1", "bar"));
configuration.add(new DisplayBlockContribution("foo", "page2", "baz"));
try {
new BeanBlockOverrideSourceImpl(cache, configuration);
unreachable();
} catch (IllegalArgumentException ex) {
assertEquals(ex.getMessage(), "The BeanBlockOverrideSource configuration contains multiple display block overrides for data type 'foo'.");
}
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class BeanBlockSourceImplTest method train_getBlock.
protected final void train_getBlock(Page page, String blockId, Block block) {
ComponentPageElement element = mockComponentPageElement();
train_getRootElement(page, element);
expect(element.getBlock(blockId)).andReturn(block);
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class TapestryModule method contributeBindingSource.
// ========================================================================
//
// Service Builder Methods (static)
//
// ========================================================================
// ========================================================================
//
// Service Contribution Methods (static)
//
// ========================================================================
/**
* Contributes the factory for several built-in binding prefixes ("asset",
* "block", "component", "literal", prop",
* "nullfieldstrategy", "message", "validate", "translate", "var").
*/
public static void contributeBindingSource(MappedConfiguration<String, BindingFactory> configuration, @InjectService("PropBindingFactory") BindingFactory propBindingFactory, @InjectService("MessageBindingFactory") BindingFactory messageBindingFactory, @InjectService("ValidateBindingFactory") BindingFactory validateBindingFactory, @InjectService("TranslateBindingFactory") BindingFactory translateBindingFactory, @InjectService("AssetBindingFactory") BindingFactory assetBindingFactory, @InjectService("NullFieldStrategyBindingFactory") BindingFactory nullFieldStrategyBindingFactory, @InjectService("ContextBindingFactory") BindingFactory contextBindingFactory, @InjectService("SymbolBindingFactory") BindingFactory symbolBindingFactory) {
configuration.add(BindingConstants.LITERAL, new LiteralBindingFactory());
configuration.add(BindingConstants.COMPONENT, new ComponentBindingFactory());
configuration.add(BindingConstants.VAR, new RenderVariableBindingFactory());
configuration.add(BindingConstants.BLOCK, new BlockBindingFactory());
configuration.add(BindingConstants.PROP, propBindingFactory);
configuration.add(BindingConstants.MESSAGE, messageBindingFactory);
configuration.add(BindingConstants.VALIDATE, validateBindingFactory);
configuration.add(BindingConstants.TRANSLATE, translateBindingFactory);
configuration.add(BindingConstants.ASSET, assetBindingFactory);
configuration.add(BindingConstants.NULLFIELDSTRATEGY, nullFieldStrategyBindingFactory);
configuration.add(BindingConstants.CONTEXT, contextBindingFactory);
configuration.add(BindingConstants.SYMBOL, symbolBindingFactory);
}
Aggregations