如何使用< dsp:a>生成动态网址在Oracle Commerce(ATG) [英] How to generate a dynamic URL using <dsp:a> in Oracle Commerce(ATG)
问题描述
我正在尝试使用ProductLookup Droplet在jsp中显示产品列表,如下所示。我还试图给出一个超链接,以导航到单个产品的产品详细信息页面。
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 individual product.
<dsp:droplet name="/atg/commerce/catalog/ProductLookup">
<dsp:param param="element.id" name="id"/>
<dsp:oparam name="output"><br/>
<dsp:a href="display_product.jsp?itemId=${id}">
Product display Name:
<b><dsp:valueof param="element.displayName"/></b><br/>
Product description Name:
<dsp:valueof param="element.description"/>
</dsp:a>
</dsp:oparam>
</dsp:droplet>
但是,我在将产品的ID传递给时遇到问题href
标签 dsp:a
。生成的HTML已将 $ {id}
硬编码为 display_product.jsp?itemId = $ {id}
。我正在获取产品列表,但URL是我面临问题的地方。如何将 element.id
中的值传递到 dsp的
? href
属性中:a
However, I'm facing issue while passing the id of the product to href
tag of dsp:a
. The resultant HTML has hardcoded ${id}
as display_product.jsp?itemId=${id}
. I'm getting list of products, but the URL is where I'm facing issue. How do I pass the value in element.id
into the href
attribute of dsp:a
?
我也试过以下内容,但没有成功。
I've also tried the following, but no success.
1。
<dsp:a href="display_product.jsp?itemId=<%=out.print(element.id) %>">
2。
<dsp:a href="display_product.jsp?itemId=<%=out.print(id) %>">
3。
<dsp:getvalueof var="id" id="id" >
<dsp:a href="display_product.jsp?itemId=${id}">
Product display Name:
<b><dsp:valueof param="element.displayName"/></b><br/>
Product description Name:
<dsp:valueof param="element.description"/>
</dsp:a>
</dsp:getvalueof>
推荐答案
要将参数传递到另一个页面,您只需使用< dsp:param>
根据下面的代码片段标记(嵌套在ProductLookup Droplet中):
To pass parameters to another page you simply use the <dsp:param>
tag as per the code fragment below (nested within your ProductLookup droplet):
这是老派的ATG方法:
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>
首选方法是使用jstl EL变量,这样可以让你的jsp更清晰,更容易阅读在引用值时允许更大的灵活性:
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>
我用 recursive =false
在上面的示例中,因为您只引用了产品的直接属性。如果你想引用属性的属性,那么你可以做这样的事情(下面的代码没有经过测试,但应该给你一般的想法):
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 }">
更新:
我仍然惊讶于很少有人知道如何做最基本的事情,比如传递参数,我已经包含了其他可以与< dsp一起使用的DSP标签: param>
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>
您可以为包含的JSP片段传递参数,这些片段使用< dsp:include>
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>
<dsp:iframe>
<dsp:img>
<dsp:link>
这篇关于如何使用< dsp:a>生成动态网址在Oracle Commerce(ATG)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!