2012-04-03 52 views
1

我想單擊一個圖像(commandLink),它重定向到一個控制器,計算點擊次數並更新對象中的一個字段返回我不希望重定向頁面,但彈出窗口應該出現讓用戶從文檔下載文件。沒有頁面重定向的命令鏈接

這是我的代碼。有人可以告訴我如何獲得輸出鏈接工作..但我的櫃檯工作正常。

<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的,行動的支持和重新呈現局部刷新頁面,但沒有工作,所以我想到了用commandlink的。

回答

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> 

這樣,你打電話給你的方法增加計數器,一旦完成,按需要在新窗口中打開文檔。