Hi all,

        Yesterday, I noticed a problem with 
ERXResponseRewriter.addStyleSheetResourceInHead(WOResponse response, WOContext 
context, String framework, String fileName, String media) method, while working 
a project. Details follow with some sample code for illustration:

        Let's say I have two components, called Main and MyComponent with the 
following contents:

        Main.html:

                <div id="contentContainer">
                        <webobject name = "MyComponent"/>
                </div>

        Main.wod:

                MyComponent : MyComponent {}



        MyComponent.html: 

                <webobject name = "MyAjaxUpdateLink"/>

        MyComponent.wod:

                MyAjaxUpdateLink : AjaxUpdateLink {
                        action = updateStuff;
                        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.javascriptTypeAttribute",
 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.




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to