action = "">
replaceID = "contentContainer";
}
MyComponent.java:
public WOActionsResult updateStuff() {
// code that updates stuff here
return null;
}
public void appendToResponse(WOResponse aResponse, WOContext aContext) {
super.appendToResponse(aResponse, aContext);
AjaxUtils.addStyleSheetResourceInHead(aContext, aResponse, "/css/my_component.css");
}
Given the above, the first time Main page is invoked, the my_component.css file is loaded inline, and everything is fine. But when the update link is clicked, the contents of the "contentContainer" div gets replaced, but the inline CSS declaration is not added again, because ERXResponseRewriter thinks the resource is already added. Looking at the ERXResponseRewriter.java I could see the code commented:
// MS: It looks like all the browsers can load CSS inline, so we don't
// even need all this.
// String fallbackStartTag;
// String fallbackEndTag;
// if (ERXAjaxApplication.isAjaxRequest(context.request())) {
// fallbackStartTag = "<script>AOD.loadCSS('";
// fallbackEndTag = "')</script>";
// }
// else {
// fallbackStartTag = null;
// fallbackEndTag = null;
// }
// ERXResponseRewriter.addResourceInHead(response, context, framework,
// fileName, cssStartTag, cssEndTag, fallbackStartTag, fallbackEndTag,
// TagMissingBehavior.SkipAndWarn);
Uncommenting it solved my problem, so I modified it a bit:
String fallbackStartTag = null;
String fallbackEndTag = null;
if (ERXAjaxApplication.isAjaxRequest(context.request()) && ERXProperties.booleanForKeyWithDefault("er.extensions.loadOnDemand", true)) {
if (ERXAjaxApplication.isAjaxReplacement(context.request()) && ERXProperties.booleanForKeyWithDefault("er.extensions.loadOnDemandDuringReplace", false)) {
boolean appendTypeAttribute = ERXProperties.booleanForKeyWithDefault("er.extensions.ERXResponseRewriter._javascript_TypeAttribute", false);
fallbackStartTag = (appendTypeAttribute ? "<script type=\"text/_javascript_\">AOD.loadCSS('" : "<script>AOD.loadCSS('");
fallbackEndTag = "')</script>";
}
}
ERXResponseRewriter.addResourceInHead(response, context, framework, fileName, cssStartTag, cssEndTag, fallbackStartTag, fallbackEndTag, TagMissingBehavior.Inline);
while looking at the ERXResponseRewriter.addScriptResourceInHead() method.
I have no idea if anyone else has ever hit this problem, but it seems to me that the commented code is needed after all. I'll file a bug report in Jira later today.
Cheers.
Bogdan Zlatanov,
Tuparev Technologies Bulgaria Ltd.