How to generate a dynamic URL using in Oracle Commerce(ATG)

前端 未结 3 396
一生所求
一生所求 2021-02-04 21:33

I\'m trying to display list of products in a jsp using ProductLookup droplet as shown below. I\'m also trying to give a hyperlink to navigate to product details page of the indi

相关标签:
3条回答
  • 2021-02-04 21:54

    Please try the following snippet. You need to use dsp:getvalueof as shown below.

    <dsp:droplet name="/atg/commerce/catalog/ProductLookup">
        <dsp:param param="element.id" name="id"/>
        <dsp:oparam name="output"><br/>
           <dsp:getvalueof id="id" param="element.id" idtype="java.lang.String">
               <dsp:a href="display_product.jsp?itemId=<%=id%>">
                   Product Name: <b><dsp:valueof param="element.displayName"/></b><br/>
                   Product description: <dsp:valueof param="element.description"/>
               </dsp:a>
           </dsp:getvalueof>
        </dsp:oparam>
    </dsp:droplet>
    
    0 讨论(0)
  • 2021-02-04 22:11

    To pass parameters to another page you simply use the <dsp:param> tag as per the code fragment below (nested within your ProductLookup droplet):

    This is the old-school ATG approach:

     <dsp:a href="display_product.jsp">
         Product Name: <b><dsp:valueof param="element.displayName"/></b><br/>
         Product description: <dsp:valueof param="element.description"/>
         <%-- this will pass the itemId parameter and value--%>
         <dsp:param name="itemId" param="element.id"/>
     </dsp:a>
    

    The preferred approach is to use jstl EL variables which makes your jsp's cleaner and easier to read, as well as allowing more flexibility when referring to the values:

    <%-- name the "element" and convert to a map  --%>
    <dsp:tomap var="product" param="element" recursive="false"/>
    <dsp:a href="display_product.jsp">
         Product Name: <b>${ product.displayName }</b><br/>
         Product description: ${ product.description }
         <dsp:param name="itemId" value="${ product.id }"/>
    </dsp:a>
    

    I have used recursive="false" in the above example because you are only referencing to direct properties of a product. If you wanted to refer to properties of properties then you could do something like this (the code below is not tested but should give you the general idea):

    <dsp:tomap var="product" param="element" recursive="true"/>
    <dsp:img page="${ product.image.url }">
    

    UPDATE:

    As I continue to be amazed how few people understand how to do even the most basic thing such as passing parameter, I have included other DSP tags which can be used in conjunction with the <dsp:param>

    You can pass parameters for included JSP fragments which use the <dsp:include>

    <dsp:tomap var="product" param="element" recursive="false"/>
    <dsp:include page="fragments/myfragment.jsp">
        <dsp:param name="itemId" value="${ product.id } />
    </dsp:include>
    

    This approach will work for these tags as well:

    • <dsp:iframe>
    • <dsp:img>
    • <dsp:link>
    0 讨论(0)
  • 2021-02-04 22:19

    @Bated answer is pretty thorough but want to add some additional information about why it is so important to use the ATG dsp tags to achieve this.


    ATG maintains your session in two ways:

    1. Via the jsessionid stored in a cookie
    2. Via the jsessionid stored in the query string

    By using the <dsp> tags you ensure that you maintain the users session as it is quite possible that the user has cookies disabled and the dsp tags will revert to using the query string.

    Using the html anchor tag is unsafe for this reason as the users session will only be maintained if they have cookies enabled.

    0 讨论(0)
提交回复
热议问题