2012-04-03 6 views
1

클릭 수를 계산하고 반환 할 때 개체의 필드를 업데이트하는 컨트롤러로 리디렉션되는 이미지 (commandLink)를 클릭하고 싶습니다. 그러나 페이지를 리디렉션하고 싶지는 않습니다. 사용자가 문서에서 파일을 다운로드 할 수있는 창이 나타납니다.명령 링크 페이지가 리디렉션되지 않음

여기 내 코드가 있습니다. 누군가가 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, action support 및 rerender를 사용하여 페이지를 새로 고치려고했으나 작동하지 않아 commandlink를 사용한다고 생각했습니다. 같은 <apex:actionStatus><apex:commandLink>

답변

0

요소는 이런 종류의 일을 수행하는 데 활용할 수있는 자바 스크립트 이벤트를, 그래서 당신의 페이지에 다음과 같이 할 것 :

<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> 

그런 식으로, 당신은 당신의 메소드를 호출을 카운터를 증가 시키면 완료되면 문서가 새 창에서 열립니다.

관련 문제