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 |
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 smime.p7s (3K) Download Attachment |
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 <[hidden email]> 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 |
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 <[hidden email]>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 <[hidden email]> > 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 |
In FTL:
${context} In screen widget: <label text="${context}"/> -Adrian On 5/4/2011 10: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<[hidden email]>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<[hidden email]> >> 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 >> >> >> >> >> > |
In reply to this post by justin.g.robinson
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. Regards Scott HotWax Media http://www.hotwaxmedia.com 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 <[hidden email]>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 <[hidden email]> >> 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 smime.p7s (3K) Download Attachment |
I've been through quite a few possible solutions, but the simplest would be
to just trigger the addOrderItem event from createSurveyResponseAndRestoreParameters using ConfigXMLReader.Event, (am not using it for XSS issues, only cause it's convenient to add code there rather then in createSurveyResponse's "simple method" ) since all the required parameters are available at that point, as opposed to using request chaining where they are lost between requests. I used: ConfigXMLReader.Event addOrderItemEvent = new ConfigXMLReader.Event("java", "com.example.OrderEvents", "addOrderItem", true); RequestMap requestMap2 = controllerConfig.getRequestMapMap().get("addOrderItem"); Using the same RequestHandler rh & ConfigXMLReader.ControllerConfig controllerConfig as the other Event but hard coding the requestUri & the second eventResponse is then "error" though no EventHandlerException is thrown. I was thinking it's maybe because the request passed to the second event [rh.runEvent(request, response, addOrderItemEvent, requestMap2, null);] is maybe in the wrong form or something. Is there any documentation around on using ConfigXMLReader.Event, or does anyone know what the problem might be off the top of their head....? On Wed, May 4, 2011 at 11:48 PM, Scott Gray <[hidden email]>wrote: > 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. > > Regards > Scott > > HotWax Media > http://www.hotwaxmedia.com > > 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 <[hidden email] > >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 <[hidden email]> > >> 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 > > -- Regards, Justin Venture-Net Research & Development |
Free forum by Nabble | Edit this page |