ISML isDefined()返回false,尽管对象在字段中包含值



我正在创建一个ISML模块,并将一个ProductBO实例传递到该模块。在提到的模块中,我试图获得OutgoingProductLinks字段,我看到它填充了我在BackOffice中定义的正确值,但当对该字段调用isDefined()时,它返回false,当我尝试在<isloop>标记中使用该字段时,它会记录错误消息,上面写着:

循环迭代器标识符"#ProductBO:ExtensibleObject:OutgoingProductLinks#"未指定有效的迭代器。

我正在处理的特定项目基于app_sf_responsed示例,因此它使用它的ViewProduct管道(它在其他盒带中没有被覆盖),该管道返回在其他几个地方使用的ProductBO对象,在那里使用的字段通常可在ISML中使用。

以下代码片段总是返回false:

<isif condition="#isDefined(ProductBO:ExtensibleObject:OutgoingProductLinks)#" >
<h1>Outgoing product links are defined</h1>
<iselse>
<h1 style="color: red;">Outgoing product links are NOT defined </h1>
</isif>

这就是我尝试实际使用提到的字段的地方:

<isloop iterator="#ProductBO:ExtensibleObject:OutgoingProductLinks#" alias="ProductLink">
//Code that uses linked products
</isloop>

请注意,对ProductBO和ExtensibleObject的isDefined()检查都在工作,问题只出现在OutgoingProductLinks 中

编辑:这是调试器显示产品链接的屏幕截图

显示有效产品链接值的调试器

添加到Johannes答案。如果你看一下演示商店的代码,这里是他们如何做到的:

//get the productlink extension from the productBO
<isset name="ProductBOProductLinksExtension" value="#ProductBO:Extension("ProductLinks")#" scope="request">
//Link type provider : example cross/up sell, replacement 
<isset name="LinkTypeProvider" value="#ProductBOProductLinksExtension:LinkTypeProvider#" scope="request">
//get the link by id from provider See ProductLinkConstants
<isset name="LinkType" value="#LinkTypeProvider:LinkTypeByID(PageletConfigurationParameters:ProductLinkType:Name)#" scope="request">
//get a collection of linked productbos
<isset name="ProductBOs" value="#ProductBOProductLinksExtension:AccessibleOutgoingLinksLinkedObjects(LinkType)#" scope="request">

优点是它只获得在线产品。

当我查看您的对象路径时

ProductBO:ExtensibleObject:OutgoingProductLinks

我可以看到您正在尝试访问底层持久化对象的API。这很好,但请确保使用名为PersistentObjectBOExtension的BOExtension。因此,代替上述使用:

ProductBO:Extension("PersistentObjectBOExtension"):PersistentObject:OutgoingProductLinks

此外,还有一个ISML函数可以检查对象路径是否表示可迭代对象:使用hasLoopElements(iterable)而不是isDefined(obj)

举个例子,整件事应该这样写:

<isif condition="#hasLoopElements(ProductBO:Extension("PersistentObjectBOExtension"):PersistentObject:OutgoingProductLinks)#" >
<h1>Outgoing product links are defined</h1>
<iselse>
<h1 style="color: red;">Outgoing product links are NOT defined </h1>
</isif>

或者,您也可以这样做来检索特定传出链接类型的产品:

<!--- Retrieve the Cross Sell products --->
<isset name="LinkedProductBOs" value="#ProductBO:SortedOutgoingProductBOLinks("ES_CrossSelling")#" scope="request"/>
<isif condition="#isDefined(LinkedProductBOs) AND hasElements(LinkedProductBOs)#">
<isloop iterator="LinkedProductBOs" alias="LinkedProductBO">
<isprint value="#LinkedProductBO:DisplayName#"/>
</isloop>
</isif>

getSortedOutgoingProductBOLinks方法将链接id作为参数。所有默认产品链接都可以在ProductLinkConstants.java中找到

最新更新