命令链接没有页面重定向

时间:2012-04-03 04:47:21

标签: apex-code visualforce

我想点击一个图像(commandLink),它重定向到控制器,计算点击次数并在返回时更新对象中的字段我不希望重定向页面但是弹出窗口应该出现让用户从Documents。下载文件。

这是我的代码。有人能告诉我如何让outputlink工作..我的计数器工作正常。

<apex:pageBlockTable value="{!Docs}" var="d" rendered="{!if(Docs.size>0,true,false)}">

<apex:column >                
 <apex:commandLink action="{!incrementCounter}">
 <apex:image url="{!URLFOR($Resource.LibraryImages)}" title="Click to Download" />  
 <apex:param assignTo="{!SelectedId}" name="selId" value="{!d.Id}"/>   
<apex:outputLink value="/servlet/servlet.FileDownload?file={!d.Document_Id__c}"/>            
 </apex:commandLink>
</apex:column>

<apex:column headerValue="Downloaded" >
   <apex:outputText value="{!d.Counter__c}" />   
  </apex:column>

</apex:pageBlockTable>

-------------------------------------------

 public pagereference incrementCounter()
    {

 UpdateCount = [select id, counter__c from Document_Details__c where id =:SelectedId];  

  Decimal num= updatecount.counter__c;
  updatecount.counter__c=num+1;
  update updatecount;

 Docs.clear();
     // to get the updated values from the object 

Docs=[Select id, Name__c, Document_Id__c,        counter__c,Uploaded_by__c,Type__c,Description__c,Document_Created_On__c,My_Library__c From

Document_Details__c where My_Library__c=: MyLib.id];


 return null;

}

我尝试使用outputlink,动作支持和rerender部分刷新页面,但这不起作用所以我想使用commandlink。

1 个答案:

答案 0 :(得分:0)

<apex:actionStatus><apex:commandLink>等元素都有javascript事件可以用来执行此类操作,因此我会在您的页面中执行以下操作:

<apex:commandLink action="{!incrementCounter}"
  oncomplete="window.open('/servlet/servlet.FileDownload?file={!d.Document_Id__c}');">
    <apex:image url="{!URLFOR($Resource.LibraryImages)}" title="Click to Download" />  
    <apex:param assignTo="{!SelectedId}" name="selId" value="{!d.Id}"/>   
</apex:commandLink>

这样,你可以调用你的方法来增加计数器,一旦完成,你可以根据需要在新窗口中打开文档。