{
String defaultFieldName = transformation.addField(Modifier.PRIVATE, fieldType, fieldName + "_default");
String invariantFieldName = transformation.addField(Modifier.PRIVATE, "boolean", fieldName + "_invariant");
BodyBuilder builder = new BodyBuilder();
builder.begin();
addDefaultBindingSetup(parameterName, defaultPrefix, defaultBinding, resourcesFieldName, transformation,
builder);
builder.addln("%s = %s.isInvariant(\"%s\");", invariantFieldName, resourcesFieldName, parameterName);
// Store the current value of the field into the default field. This value will
// be used to reset the field after rendering.
builder.addln("%s = %s;", defaultFieldName, fieldName);
builder.end();
transformation.extendMethod(TransformConstants.CONTAINING_PAGE_DID_LOAD_SIGNATURE, builder
.toString());
// Now, when the component completes rendering, ensure that any variant parameters are
// are returned to default value. This isn't necessary when the parameter is not cached,
// because (unless the binding is invariant), there's no value to get rid of (and if it is
// invariant, there's no need to get rid of it).
if (cache)
{
builder.clear();
builder.addln("if (! %s)", invariantFieldName);
builder.begin();
builder.addln("%s = %s;", fieldName, defaultFieldName);
builder.addln("%s = false;", cachedFieldName);
builder.end();
transformation.extendMethod(TransformConstants.POST_RENDER_CLEANUP_SIGNATURE, builder
.toString());
}
return invariantFieldName;
}