use of org.apache.tapestry5.services.Core in project tapestry-5 by apache.
the class AjaxFormLoop method setupRender.
void setupRender(MarkupWriter writer) {
pushContext();
iterator = source == null ? Collections.EMPTY_LIST.iterator() : source.iterator();
Link removeRowLink = resources.createEventLink("triggerRemoveRow", context);
Link injectRowLink = resources.createEventLink("injectRow", context);
injectRowLink.addParameter(RequestConstants.FORM_CLIENTID_PARAMETER, formSupport.getClientId());
injectRowLink.addParameter(RequestConstants.FORM_COMPONENTID_PARAMETER, formSupport.getFormComponentId());
// Fix for TAP5-227 - AjaxFormLoop dont work well inside a table tag
Element element = writer.getElement();
this.wrapper = element.getAttribute("data-container-type") != null || element.getAttribute("data-remove-row-url") != null || element.getAttribute("data-inject-row-url") != null ? writer.element("div") : null;
writer.attributes("data-container-type", "core/AjaxFormLoop", "data-remove-row-url", removeRowLink, "data-inject-row-url", injectRowLink);
}
use of org.apache.tapestry5.services.Core in project tapestry-5 by apache.
the class Select method beginRender.
void beginRender(MarkupWriter writer) {
writer.element("select", "name", getControlName(), "id", getClientId(), "class", cssClass);
putPropertyNameIntoBeanValidationContext("value");
validate.render(writer);
removePropertyNameFromBeanValidationContext();
resources.renderInformalParameters(writer);
decorateInsideField();
if (this.zone != null) {
javaScriptSupport.require("t5/core/select");
Link link = resources.createEventLink(CHANGE_EVENT, context);
writer.attributes("data-update-zone", zone, "data-update-url", link);
}
}
use of org.apache.tapestry5.services.Core in project tapestry-5 by apache.
the class TapestryModule method contributeTypeCoercer.
/**
* Adds coercions:
* <ul>
* <li>String to {@link SelectModel}
* <li>Map to {@link SelectModel}
* <li>Collection to {@link GridDataSource}
* <li>null to {@link GridDataSource}
* <li>List to {@link SelectModel}
* <li>{@link ComponentResourcesAware} (typically, a component) to {@link ComponentResources}
* <li>{@link ComponentResources} to {@link PropertyOverrides}
* <li>String to {@link Renderable}
* <li>{@link Renderable} to {@link Block}
* <li>String to {@link DateFormat}
* <li>String to {@link Resource} (via {@link AssetSource#resourceForPath(String)})
* <li>{@link Renderable} to {@link RenderCommand}</li>
* <li>String to {@link Pattern}</li>
* <li>String to {@link DateFormat}</li>
* <li>{@link Resource} to {@link DynamicTemplate}</li>
* <li>{@link Asset} to {@link Resource}</li>
* <li>{@link ValueEncoder} to {@link ValueEncoderFactory}</li>
* </ul>
*/
public static void contributeTypeCoercer(MappedConfiguration<CoercionTuple.Key, CoercionTuple> configuration, final ObjectLocator objectLocator, @Builtin final ThreadLocale threadLocale, @Core final AssetSource assetSource, @Core final DynamicTemplateParser dynamicTemplateParser) {
CoercionTuple<ComponentResources, PropertyOverrides> componentResourcesToPropertyOverrides = CoercionTuple.create(ComponentResources.class, PropertyOverrides.class, new Coercion<ComponentResources, PropertyOverrides>() {
public PropertyOverrides coerce(ComponentResources input) {
return new PropertyOverridesImpl(input);
}
});
configuration.add(componentResourcesToPropertyOverrides.getKey(), componentResourcesToPropertyOverrides);
// See TAP5-2184 for why this causes some trouble!
CoercionTuple<String, SelectModel> stringToSelectModel = CoercionTuple.create(String.class, SelectModel.class, new Coercion<String, SelectModel>() {
public SelectModel coerce(String input) {
return TapestryInternalUtils.toSelectModel(input);
}
});
configuration.add(stringToSelectModel.getKey(), stringToSelectModel);
CoercionTuple<Map, SelectModel> mapToSelectModel = CoercionTuple.create(Map.class, SelectModel.class, new Coercion<Map, SelectModel>() {
@SuppressWarnings("unchecked")
public SelectModel coerce(Map input) {
return TapestryInternalUtils.toSelectModel(input);
}
});
configuration.add(mapToSelectModel.getKey(), mapToSelectModel);
CoercionTuple<Collection, GridDataSource> collectionToGridDataSource = CoercionTuple.create(Collection.class, GridDataSource.class, new Coercion<Collection, GridDataSource>() {
public GridDataSource coerce(Collection input) {
return new CollectionGridDataSource(input);
}
});
configuration.add(collectionToGridDataSource.getKey(), collectionToGridDataSource);
CoercionTuple<Void, GridDataSource> voidToGridDataSource = CoercionTuple.create(void.class, GridDataSource.class, new Coercion<Void, GridDataSource>() {
private final GridDataSource source = new NullDataSource();
public GridDataSource coerce(Void input) {
return source;
}
});
configuration.add(voidToGridDataSource.getKey(), voidToGridDataSource);
CoercionTuple<List, SelectModel> listToSelectModel = CoercionTuple.create(List.class, SelectModel.class, new Coercion<List, SelectModel>() {
private SelectModelFactory selectModelFactory;
@SuppressWarnings("unchecked")
public SelectModel coerce(List input) {
// to another value, and a race condition is harmless.
if (selectModelFactory == null) {
selectModelFactory = objectLocator.getService(SelectModelFactory.class);
}
return selectModelFactory.create(input);
}
});
configuration.add(listToSelectModel.getKey(), listToSelectModel);
CoercionTuple<String, Pattern> stringToPattern = CoercionTuple.create(String.class, Pattern.class, new Coercion<String, Pattern>() {
public Pattern coerce(String input) {
return Pattern.compile(input);
}
});
configuration.add(stringToPattern.getKey(), stringToPattern);
CoercionTuple<ComponentResourcesAware, ComponentResources> componentResourcesAwareToComponentResources = CoercionTuple.create(ComponentResourcesAware.class, ComponentResources.class, new Coercion<ComponentResourcesAware, ComponentResources>() {
public ComponentResources coerce(ComponentResourcesAware input) {
return input.getComponentResources();
}
});
configuration.add(componentResourcesAwareToComponentResources.getKey(), componentResourcesAwareToComponentResources);
CoercionTuple<String, Renderable> stringToRenderable = CoercionTuple.create(String.class, Renderable.class, new Coercion<String, Renderable>() {
public Renderable coerce(String input) {
return new StringRenderable(input);
}
});
configuration.add(stringToRenderable.getKey(), stringToRenderable);
CoercionTuple<Renderable, Block> renderableToBlock = CoercionTuple.create(Renderable.class, Block.class, new Coercion<Renderable, Block>() {
public Block coerce(Renderable input) {
return new RenderableAsBlock(input);
}
});
configuration.add(renderableToBlock.getKey(), renderableToBlock);
CoercionTuple<String, DateFormat> stringToDateFormat = CoercionTuple.create(String.class, DateFormat.class, new Coercion<String, DateFormat>() {
public DateFormat coerce(String input) {
final SimpleDateFormat dateFormat = new SimpleDateFormat(input, threadLocale.getLocale());
final String lenient = objectLocator.getService(SymbolSource.class).valueForSymbol(SymbolConstants.LENIENT_DATE_FORMAT);
dateFormat.setLenient(Boolean.parseBoolean(lenient));
return dateFormat;
}
});
configuration.add(stringToDateFormat.getKey(), stringToDateFormat);
CoercionTuple<String, Resource> stringToResource = CoercionTuple.create(String.class, Resource.class, new Coercion<String, Resource>() {
public Resource coerce(String input) {
return assetSource.resourceForPath(input);
}
});
configuration.add(stringToResource.getKey(), stringToResource);
CoercionTuple<Renderable, RenderCommand> renderableToRenderCommand = CoercionTuple.create(Renderable.class, RenderCommand.class, new Coercion<Renderable, RenderCommand>() {
public RenderCommand coerce(final Renderable input) {
return new RenderCommand() {
public void render(MarkupWriter writer, RenderQueue queue) {
input.render(writer);
}
};
}
});
configuration.add(renderableToRenderCommand.getKey(), renderableToRenderCommand);
CoercionTuple<Date, Calendar> dateToCalendar = CoercionTuple.create(Date.class, Calendar.class, new Coercion<Date, Calendar>() {
public Calendar coerce(Date input) {
Calendar calendar = Calendar.getInstance(threadLocale.getLocale());
calendar.setTime(input);
return calendar;
}
});
configuration.add(dateToCalendar.getKey(), dateToCalendar);
CoercionTuple<Resource, DynamicTemplate> resourceToDynamicTemplate = CoercionTuple.create(Resource.class, DynamicTemplate.class, new Coercion<Resource, DynamicTemplate>() {
public DynamicTemplate coerce(Resource input) {
return dynamicTemplateParser.parseTemplate(input);
}
});
configuration.add(resourceToDynamicTemplate.getKey(), resourceToDynamicTemplate);
CoercionTuple<Asset, Resource> assetToResource = CoercionTuple.create(Asset.class, Resource.class, new Coercion<Asset, Resource>() {
public Resource coerce(Asset input) {
return input.getResource();
}
});
configuration.add(assetToResource.getKey(), assetToResource);
CoercionTuple<ValueEncoder, ValueEncoderFactory> valueEncoderToValueEncoderFactory = CoercionTuple.create(ValueEncoder.class, ValueEncoderFactory.class, new Coercion<ValueEncoder, ValueEncoderFactory>() {
public ValueEncoderFactory coerce(ValueEncoder input) {
return new GenericValueEncoderFactory(input);
}
});
configuration.add(valueEncoderToValueEncoderFactory.getKey(), valueEncoderToValueEncoderFactory);
}
use of org.apache.tapestry5.services.Core in project tapestry-5 by apache.
the class JavaScriptModule method setupCoreJavaScriptStack.
/**
* The core JavaScriptStack has a number of entries:
* <dl>
* <dt>requirejs</dt> <dd>The RequireJS AMD JavaScript library</dd>
* <dt>scriptaculous.js, effects.js</dt> <dd>Optional JavaScript libraries in compatibility mode (see {@link Trait#SCRIPTACULOUS})</dd>
* <dt>t53-compatibility.js</dt> <dd>Optional JavaScript library (see {@link Trait#INITIALIZERS})</dd>
* <dt>underscore-library, underscore-module</dt>
* <dt>The Underscore JavaScript library, and the shim that allows underscore to be injected</dt>
* <dt>t5/core/init</dt> <dd>Optional module related to t53-compatibility.js</dd>
* <dt>jquery-library</dt> <dd>The jQuery library</dd>
* <dt>jquery-noconflict</dt> <dd>Switches jQuery to no-conflict mode (only present when the infrastructure is "prototype").</dd>
* <dt>jquery</dt> <dd>A module shim that allows jQuery to be injected (and also switches jQuery to no-conflict mode)</dd>
* <dt>bootstrap.css, tapestry.css, exception-frame.css, tapestry-console.css, tree.css</dt>
* <dd>CSS files</dd>
* <dt>t5/core/[...]</dt>
* <dd>Additional JavaScript modules</dd>
* <dt>jquery</dt>
* <dd>Added if the infrastructure provider is "jquery".</dd>
* </dl>
*
* User modules may replace or extend this list.
*/
@Contribute(JavaScriptStack.class)
@Core
public static void setupCoreJavaScriptStack(OrderedConfiguration<StackExtension> configuration, Compatibility compatibility, @Symbol(SymbolConstants.JAVASCRIPT_INFRASTRUCTURE_PROVIDER) String provider) {
configuration.add("requirejs", StackExtension.library(ROOT + "/require.js"));
configuration.add("underscore-library", StackExtension.library(ROOT + "/underscore-1.8.3.js"));
if (provider.equals("prototype")) {
final String SCRIPTY = "${tapestry.scriptaculous}";
add(configuration, StackExtensionType.LIBRARY, SCRIPTY + "/prototype.js");
if (compatibility.enabled(Trait.SCRIPTACULOUS)) {
add(configuration, StackExtensionType.LIBRARY, SCRIPTY + "/scriptaculous.js", SCRIPTY + "/effects.js");
}
}
if (compatibility.enabled(Trait.INITIALIZERS)) {
add(configuration, StackExtensionType.LIBRARY, ROOT + "/t53-compatibility.js");
configuration.add("t5/core/init", new StackExtension(StackExtensionType.MODULE, "t5/core/init"));
}
configuration.add("jquery-library", StackExtension.library(ROOT + "/jquery.js"));
if (provider.equals("prototype")) {
configuration.add("jquery-noconflict", StackExtension.library(ROOT + "/jquery-noconflict.js"));
}
add(configuration, StackExtensionType.MODULE, "jquery");
add(configuration, StackExtensionType.STYLESHEET, "${" + SymbolConstants.FONT_AWESOME_ROOT + "}/css/font-awesome.css");
if (compatibility.enabled(Trait.BOOTSTRAP_3) && compatibility.enabled(Trait.BOOTSTRAP_4)) {
throw new RuntimeException("You cannot have Trait.BOOTSTRAP_3 and Trait.BOOTSTRAP_4 enabled at the same time. Check your contributions to the Compatibility service.");
}
if (compatibility.enabled(Trait.BOOTSTRAP_3)) {
addCoreStylesheets(configuration, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap.css");
}
if (compatibility.enabled(Trait.BOOTSTRAP_4)) {
addCoreStylesheets(configuration, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap.css");
add(configuration, StackExtensionType.STYLESHEET, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap-grid.css");
}
if (!compatibility.enabled(Trait.BOOTSTRAP_3) && !compatibility.enabled(Trait.BOOTSTRAP_4)) {
configuration.add("defaultcss", StackExtension.stylesheet("${" + SymbolConstants.DEFAULT_STYLESHEET + "}"));
}
for (String name : bundledModules) {
String full = "t5/core/" + name;
configuration.add(full, StackExtension.module(full));
}
configuration.add("underscore-module", StackExtension.module("underscore"));
}
use of org.apache.tapestry5.services.Core in project tapestry-5 by apache.
the class JavaScriptModule method setupBaseModules.
@Contribute(ModuleManager.class)
public static void setupBaseModules(MappedConfiguration<String, Object> configuration, @Path("${tapestry.asset.root}/underscore-shim.js") Resource underscoreShim, @Path("${tapestry.asset.root}/jquery-shim.js") Resource jqueryShim, @Path("${tapestry.asset.root}/typeahead.js") Resource typeahead, @Path("${tapestry.asset.root}/moment-2.15.1.js") Resource moment, @Path("${tapestry.asset.root}/bootstrap/js/transition.js") Resource transition, @Path("${tapestry.asset.root}/bootstrap4/js/bootstrap-util.js") Resource bootstrapUtil, Compatibility compatibility) {
// The underscore shim module allows Underscore to be injected
configuration.add("underscore", new JavaScriptModuleConfiguration(underscoreShim));
configuration.add("jquery", new JavaScriptModuleConfiguration(jqueryShim));
if (compatibility.enabled(Trait.BOOTSTRAP_3)) {
final String[] modules = new String[] { "affix", "alert", "button", "carousel", "collapse", "dropdown", "modal", "scrollspy", "tab", "tooltip" };
addBootstrap3Modules(configuration, transition, modules);
Resource popover = transition.forFile("popover.js");
configuration.add("bootstrap/popover", new AMDWrapper(popover).require("bootstrap/tooltip").asJavaScriptModuleConfiguration());
}
if (compatibility.enabled(Trait.BOOTSTRAP_4)) {
configuration.add("bootstrap/bootstrap-util", new JavaScriptModuleConfiguration(bootstrapUtil));
configuration.add("bootstrap/popper", new JavaScriptModuleConfiguration(bootstrapUtil.forFile("popper.js")));
for (String name : new String[] { "alert", "button", "carousel", "collapse", "dropdown", "modal", "scrollspy", "tab", "tooltip" }) {
Resource lib = bootstrapUtil.forFile(name + ".js");
if (lib.exists()) {
configuration.add("bootstrap/" + name, new JavaScriptModuleConfiguration(lib).dependsOn("bootstrap/bootstrap-util").dependsOn("bootstrap/popper"));
}
}
}
// is completely disabled
if (!compatibility.enabled(Trait.BOOTSTRAP_3) && !compatibility.enabled(Trait.BOOTSTRAP_4)) {
final String[] modules = new String[] { "alert", "dropdown", "collapse" };
addBootstrap3Modules(configuration, transition, modules);
}
configuration.add("t5/core/typeahead", new JavaScriptModuleConfiguration(typeahead).dependsOn("jquery"));
configuration.add("moment", new JavaScriptModuleConfiguration(moment));
}
Aggregations