use of org.apache.ofbiz.widget.cache.WidgetContextCacheKey in project ofbiz-framework by apache.
the class ScreenRenderer method render.
/**
* Renders the named screen using the render environment configured when this ScreenRenderer was created.
*
* @param resourceName The name/location of the resource to use, can use "component://[component-name]/" and "ofbiz://" and other special OFBiz style URLs
* @param screenName The name of the screen within the XML file specified by the resourceName.
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
*/
public String render(String resourceName, String screenName) throws GeneralException, IOException, SAXException, ParserConfigurationException {
ModelScreen modelScreen = ScreenFactory.getScreenFromLocation(resourceName, screenName);
if (modelScreen.getUseCache()) {
// if in the screen definition use-cache is set to true
// then try to get an already built screen output from the cache:
// 1) if we find it then we get it and attach it to the passed in writer
// 2) if we can't find one, we create a new StringWriter,
// and pass it to the renderScreenString;
// then we wrap its content and put it in the cache;
// and we attach it to the passed in writer
WidgetContextCacheKey wcck = new WidgetContextCacheKey(context);
String screenCombinedName = resourceName + ":" + screenName;
ScreenCache screenCache = new ScreenCache();
GenericWidgetOutput gwo = screenCache.get(screenCombinedName, wcck);
if (gwo == null) {
Writer sw = new StringWriter();
modelScreen.renderScreenString(sw, context, screenStringRenderer);
gwo = new GenericWidgetOutput(sw.toString());
screenCache.put(screenCombinedName, wcck, gwo);
writer.append(gwo.toString());
} else {
writer.append(gwo.toString());
}
} else {
context.put("renderFormSeqNumber", String.valueOf(renderFormSeqNumber));
modelScreen.renderScreenString(writer, context, screenStringRenderer);
}
return "";
}
Aggregations