Cmobilecom AF 5.19 Developer Guide

23.1 Web Resources

Web resources include javascripts and style sheets. They can be static and dynamic. Static resources are always added into page, but dynamic resources are added into page only when they are needed.

Static resources

Core resources such as AF.js and AF.css are static and always added to page.

Resource dependencies declared by modules are static. For example,


@ResourceDependencies({
	// META-INF/resources/cmobilecom/module/hr/employee.js
	@ResourceDependency(library="cmobilecom", 
			name="module/hr/employee.js")
})
public class WebHRModule extends HRModule implements WebModule {

	...
}
If a module is included in an instance type, all pages of the instance type will have the module static resources added into page.

Dynamic resources

JSF UI component resources and BeanViewEncoder resources are dynamic, and they are added to page only when they are rendered.

UI component example:

@ResourceDependencies({
	// META-INF/resources/cmobilecom/mycomponent.js
	@ResourceDependency(library="cmobilecom", name="mycomponent.js")
})
public class MyComponent extends UIInput {
	...
}
BeanViewEncoder resources are dynamic. For example,

public class MyBeanViewEncoder extends EntityBeanViewEncoder<MyType> {

	// define dynamic web resources
	@Override
	protected List<WebResource> getWidgetResources(String widgetType) {
		if ("EmployeeBean".equals(widgetType)) {
			// module name: lowercase in file path and URL
			// META-INF/resources/cmobilecom/module/hr/employee.js
			WebResource resource = new WebResource("hr",
					"employee.js", "cmobilecom", false, true);
			return Arrays.asList(resource);
		}

		return super.getWidgetResources(widgetType);
	}
	
}
See Bean View Encoder for detail.
ExtensionsBean View EncoderFrames / No Frames