Salesforce Visualforce将静态资源URL传递给Apex

Salesforce Visualforce将静态资源URL传递给Apex,salesforce,apex-code,visualforce,Salesforce,Apex Code,Visualforce,我试图通过apex:param标记传递一个静态资源URL。到目前为止,我掌握的代码是: 视觉力: <apex:selectList value="{!SelectedFamily}" onchange="renderGallery();" size="1" label="Product Family"> <apex:actionFunction name="renderGallery" rerender="gallery" oncomplete="renderScrip

我试图通过apex:param标记传递一个静态资源URL。到目前为止,我掌握的代码是:

视觉力:

<apex:selectList value="{!SelectedFamily}" onchange="renderGallery();" size="1" label="Product Family">
    <apex:actionFunction name="renderGallery" rerender="gallery" oncomplete="renderScripts();">
        <apex:param value="{!URLFOR($Resource.NoImage)}" assignTo="{!noImage}"/>
        <apex:param value="{!URLFOR($Resource.NoImageThumb)}" assignTo="{!noImageThumb}"/>
    </apex:actionFunction>
    <apex:actionFunction name="renderScripts" rerender="scriptPanel"> 
    </apex:actionFunction>
    <apex:selectOptions value="{!Family}" />
</apex:selectList>
我对apex:param的理解是,我现在可以在重新呈现之后调用控制器变量,并且它们将被静态资源URL填充。但不幸的是,我一直得到零

有人知道它为什么不工作吗?

{!URLFOR($Resource.NoImage)}不是用来作为控制器/扩展变量的。它直接引用静态资源(不需要控制器/扩展)

我建议您使用带有渲染属性的输出面板,该属性绑定到由action函数控制的Apex变量。这样,您可以通过显示或隐藏输出面板来显示或隐藏图像的每个版本

或者,您可能希望研究如何使用类似的工具

{!URLFOR($Resource.NoImage)}
不打算用作控制器/扩展变量。它直接引用静态资源(不需要控制器/扩展)

我建议您使用带有渲染属性的输出面板,该属性绑定到由action函数控制的Apex变量。这样,您可以通过显示或隐藏输出面板来显示或隐藏图像的每个版本


或者,您可能希望研究如何使用类似的工具

如果您为参数提供名称,它就可以工作——Visualforce不会在此上下文中处理参数,除非它们被命名

<apex:actionFunction name="renderGallery" rerender="gallery" oncomplete="renderScripts();">
       <apex:param name="noImg" value="{!URLFOR($Resource.NoImage)}" assignTo="{!noImage}"/>
       <apex:param name="noImgUrl" value="{!URLFOR($Resource.NoImageThumb)}" assignTo="{!noImageThumb}"/>
</apex:actionFunction>

如果这不能立即对您起作用,请发布Visualforce代码的其余部分,这样我们就可以看到“gallery”和“scriptPanel”与apex表单标记的关系——让rerender正常工作是出了名的棘手,并且完全取决于重新渲染的DOM元素的层次位置。要确保gallery和scriptPanel成功重新渲染,请将它们放在apex form标记外的单独OutputPanel中,如下所示:

<apex:outputPanel id="scriptPanel">
     Selected Family: {!SelectedFamily}<br/>
</apex:outputPanel><br/><br/>


<apex:outputPanel id="gallery">
     No Image: {!noImage}<br/>
     No Image Thumb: {!noImageThumb}<br/>
</apex:outputPanel><br/><br/>

所选族:{!SelectedFamily}


没有图像:{!noImage}
无图像拇指:{!noImageThumb}



@MatthewKeefe,{!URLFOR()}完全没有理由不能用作扩展变量——它编译为文本(例如,/resource/123718923'),因此Jim在这里的解决方案实际上非常有趣,因为它使他不必对控制器中的StaticResource对象执行SOQL查询。

如果您为参数提供名称,它会起作用——Visualforce不会在该上下文中处理参数,除非它们被命名

<apex:actionFunction name="renderGallery" rerender="gallery" oncomplete="renderScripts();">
       <apex:param name="noImg" value="{!URLFOR($Resource.NoImage)}" assignTo="{!noImage}"/>
       <apex:param name="noImgUrl" value="{!URLFOR($Resource.NoImageThumb)}" assignTo="{!noImageThumb}"/>
</apex:actionFunction>

如果这不能立即对您起作用,请发布Visualforce代码的其余部分,这样我们就可以看到“gallery”和“scriptPanel”与apex表单标记的关系——让rerender正常工作是出了名的棘手,并且完全取决于重新渲染的DOM元素的层次位置。要确保gallery和scriptPanel成功重新渲染,请将它们放在apex form标记外的单独OutputPanel中,如下所示:

<apex:outputPanel id="scriptPanel">
     Selected Family: {!SelectedFamily}<br/>
</apex:outputPanel><br/><br/>


<apex:outputPanel id="gallery">
     No Image: {!noImage}<br/>
     No Image Thumb: {!noImageThumb}<br/>
</apex:outputPanel><br/><br/>

所选族:{!SelectedFamily}


没有图像:{!noImage}
无图像拇指:{!noImageThumb}



@MatthewKeefe,{!URLFOR()}绝对没有理由不能用作扩展变量——它编译为文本(例如,/resource/123718923'),因此Jim在这里的解决方案实际上非常有趣,因为它使他不必对控制器中的StaticResource对象执行SOQL查询。

Nice,很高兴你能让它工作。另外,针对我的回答的评论应该是对我的回答的评论,而不是在你的回答中。谢谢马修——我想对你的帖子发表评论,但我不能。也许我必须有更高的声誉?很好,很高兴你能让它发挥作用。另外,针对我的回答的评论应该是对我的回答的评论,而不是在你的回答中。谢谢马修——我想对你的帖子发表评论,但我不能。也许我必须有更高的声誉?