Use the OOTB Factory Producer and Factory Implementations
Use Your Own Factory Implementation
Use the @ServiceProducer Annotation (tools.gsf.config.ServiceProducer)
Use the @InjectForRequest Annotation (tools.gsf.config.inject.InjectForRequest)
Use the @Bind Annotation (tools.gsf.config.inject.Bind)
Use the @CurrentAsset Annotation (tools.gsf.facade.assetapi.asset.CurrentAsset)
Use the @Mapping Annotation (tools.gsf.mapping.Mapping)
Use Your Own Asset Type as a GST Property Asset
Adding the GSF to your project does not require any special setup or configuration. To begin leveraging the features of gsf-core, simply add gsf-core-VERSION.jar to your project's Java classpath.
Factory myIcsScopedFactory = FactoryLocator.locateFactory(ics); // ics is your ICS instance
FactoryProducer fp = FactoryProducer.locateFactoryProducer(servletContext); // servletContext is your ServletContext instance Factory myServletContextScopedFactory = fp.getFactory(servletContext);
COM.FutureTense.Interfaces.ICS:foo.wee.whatever.MyCustomIcsBackedFactory
javax.servlet.ServletContext:foo.wee.whatever.MyCustomServletContextBackedFactory
COM.FutureTense.Interfaces.ICS:tools.gsf.config.IcsBackedFactory javax.servlet.ServletContext:tools.gsf.config.ServletContextBackedFactory
(...) @ServiceProducer public Stopwatch newStopwatch() { return LoggerStopwatch.getInstance(); } (...)
(NOTE: you can find multiple examples inside the IcsBackedFactory and ServletContextBackedFactory classes)
(...) /** * Provide a DAO that allows an asset to be easily mapped */ @InjectForRequest protected TemplateAssetAccess templateAssetAccess; (...)
(...) /** * Bind rendermode to local variable */ @Bind(value="rendermode") protected String myRenderMode; (...)
class MyController extends InjectingController { (...) @CurrentAsset(attributes=["title", "body", "headline"]) TemplateAsset currentTemplateAsset; protected void handleRequest() { String headline = currentAsset.asString("headline"); (...) } (...) }
class AnotherController extends InjectingController { (...) @CurrentAsset(attributes=["title", "body", "headline"]) ScatteredAsset currentScatteredAsset; protected void handleRequest() { models.add("asset", currentScatteredAsset); (...) } (...) }
class ThirdController extends InjectingController { (...) @CurrentAsset(attributes=["title", "body", "headline"]) AssetData currentAssetData; protected void handleRequest() { AttributeData ad = currentAssetData.getAttribute("title"); (...) } (...) }
(...) /** * Bind map entry's value to local variable */ @Mapping(value="myMappedAsset") protected String mappedAsset; (...)
@ServiceProducer(cache = true) public PropertyDao instantiateCustomPropertyDao(final ICS ics) { Session session = SessionFactory.getSession(ics); AssetDataManager adm = (AssetDataManager) session.getManager(AssetDataManager.class.getName()); SiteManager sm = (SiteManager) session.getManager(SiteManager.class.getName()); String type = "MyCustomAssetType"; String flexDefName = "MyCustomFlexDefName"; String propNameAttr = "nameOfAttributeToGetThePropertyNameFrom"; \\ Typically "name" String propDescAttr = "nameOfAttributeToGetThePropertyDescriptionFrom"; \\ Typically "description" String propValueAttr = "nameOfAttributeToGetThePropertyValueFrom"; \\ Typically "value" return new AssetApiPropertyDao(adm, sm, type, flexDefName, propNameAttr, propDescAttr, propValueAttr, ics); }
See "Use a Custom Asset Type as a GST Property Asset" and "Implement (and Use) Your Own NavService Implementation" above.
In general, all you need to do is implement your own object factory and make your custom bean available by adding the due Service Producer (annotated) method to it.
If you are curious (or suspicious) as to how this works, look at the source code for GSF's InjectingController.java. It's trivially short.
WCS 12c will not invoke your Template's controller if you invoke your template using a render:calltemplate tag call with style="element".
In such scenario, if your Template's code depended on its own Controller's logic (which is usually the case), it would break.
Previous versions of the GSF defaulted to style="element" when Type 1 actions called the childpagename template (in an attempt to intelligently set the call's style whenever you didn't set it explicitly).
This did not occur in WCS 11.x and previous versions since Controllers were just introduced in WCS 12c.
If you are using the GST/Dispatcher wrapper, GSF actions or any other LEGACY (hence deprecated) feature related to those two, be aware that combining those with the use of WCS 12c Controllers may yield erratic behaviour for the same reason.
You can work around this by:
In addition to this, if you really need to use GSF Actions AND Controllers, here are some ideas to minimize chance of your CallTemplate calls breaking (DISCLAIMER: as per the above explanation, these may not cover you 100%):
From the above, you've probably figured out already that GSF deals with the potential chaos this style-related behaviour could cause on pre-existing code you attempt migrating to WCS 12c's Controller-based paradigm simply by getting rid of the "legacy" intelligence.
This implies there are now 2 CallTemplate facades: