ofbiz-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Gray <scott.g...@hotwaxmedia.com>
Subject Re: FreeMarker requestAttribute issue
Date Wed, 04 May 2011 21:48:11 GMT
My memory is pretty vague on this but the parameters from the initial add to cart call are
stashed in the session while the survey is sent to the user.  Once the user completes the
survey and submits it then the parameters are pulled back out of the session and the add to
cart call proceeds as normal.  I only remember that because I implemented it due to XSS issues
that were present in the previous implementation where the survey form was being used to pass
around unknown parameters as hidden fields in order to maintain state across the two requests.

You should see in the original ShoppingCartEvents code a call to UtilHttp.stashParameterMap(...)
and then later to UtilHttp.restoreStashedParameterMap(...).  The string returned from the
stash call should be included in the survey form as a hidden field and then used later to
retrieve the original parameters so that the add to cart code can function correctly.

Controller events occur prior to the start of screen rendering so request attributes are at
that point the only form of context available (along with request parameters, session attributes
and the webapp context).  Once screen rendering begins a combined map of those sources is
generated and used as the screen's context from that point forward.


HotWax Media

On 5/05/2011, at 5:23 AM, Justin Robinson wrote:

> Now I have another problem also related to the context and what's avaiable
> at times in between requests.
> When a survey is encountered attached to the product being added to the cart
> in, addOrderItem in OrderEvents, the addorderItem service returns "survey"
> which then calls the ftl & groovy script that all works fine. But when the
> answers have been entered and the form submitted (A SurveyResponse entity is
> created and stored) it then calls addOrderItem again but this time the order
> item doesn't get added because the productId is no longer available in the
> context, at least that seems to be the reason.
> Doubtless it's related and the issue has been encountered before because
> besides the simple-method method-name="createSurveyResponse" in
> SurveyServices.xml of the content app, there's also another service
> createSurveyResponseAndRestoreParameters in SurveyEvents of the content app.
> I tried using this instead but it still doesn't work.
> I can't get my head around the context and request parameters thing, if only
> there was some way to see what was in it at any time. The only thing I can
> think of is to pass the productId and other required parameters through the
> createSurveyResponseAndRestoreParameters or a  new service based on it as
> INOUT so they are available on the other side of the request, have yet to
> try this...
> But there must be a better way?
> On Wed, May 4, 2011 at 4:55 PM, Justin Robinson <justin@venturenet.co.za>wrote:
>> Brilliant thanks...for saving me some time... been reading the freemarker
>> manual & looking at the the ofbiz freemarker framework all afternoon.
>> *That code was on OrderEvents but I moved it to a groovy script, were all
>> the parameters gotten from the request seem to be available anyway.*
>> On Wed, May 4, 2011 at 2:49 PM, Scott Gray <scott.gray@hotwaxmedia.com>
>> wrote:
>>> You need to put it in the screen context and not in the request
>> attributes, if you're using groovy then it's just:
>>> context.surveyWrapper = surveyWrapper
>>> Reason being that the request attributes (and session attributes and
>> parameters) have already been placed in the context at the start of the
>> screen rendering and your actions are occurring after that point.
>>> Regards
>>> Scott
>>> HotWax Media
>>> http://www.hotwaxmedia.com
>>> On 4/05/2011, at 9:55 PM, Justin Robinson wrote:
>>>> surveyWrapper?has_content always returns false no matter that the
>>>> debug shows that it's not null when it's set.
>>>> Have tried setting it as a session attribute, with no effect.
>>>> Am really stumped on this one no idea what to try....Any ideas?
>>>> the ftl:
>>>> <div class="screenlet">
>>>>   <div class="screenlet-body">
>>>>       <#-- Render the survey -->
>>>>       <#if surveyWrapper?has_content>
>>>>           <form method="post" enctype="multipart/form-data"
>>>> action="<@ofbizUrl>profilesurvey/profilesurvey</@ofbizUrl>"
>>>> style="margin: 0;">
>>>>             ${surveyWrapper.render()}
>>>>           </form>
>>>>       <#else>
>>>>           <h1>Survey Failed</h1>
>>>>           <p>surveyWrapper?has_content returned false</p>
>>>>       </#if>
>>>>   </div>
>>>> </div>
>>>> code that sets the surveyWrapper:
>>>> // set up a surveyAction and surveyWrapper, then redirect to survey
>>>> ProductStoreSurveyWrapper wrapper = new
>>>> ProductStoreSurveyWrapper(surveys.get(0), cart.getOrderPartyId(),
>>>> UtilHttp.getParameterMap(request));
>>>> Debug.log("wrapper: "+(wrapper!=null? "not null":"null"), MODULE);
>>>> request.setAttribute("surveyWrapper", wrapper);
>>>> request.getSession().setAttribute("surveyWrapper", wrapper);
>>>> request.setAttribute("surveyAction", "addOrderItemSurvey")
>>>> Regards,
>>>> Justin
>>>> Venture-Net Research & Development
>> --
>> Regards,
>> Justin
>> Venture-Net Research & Development
> -- 
> Regards,
> Justin
> Venture-Net Research & Development

View raw message