+ Start a Discussion
HaroldHarold 

Using controller to build custom url before opening new window

So I have a need to build a custom url that is built from an object and soql queries.  It's for a custom report screen.  

 

Basically the flow is like this:  The user clicks on a report link that should fire a controller method that sends the report name to a controller method, the method uses the report name and a custom object and soql to build a report url.  Then a window.open should be done in the vf page to open that url into a new window.  

 

Here is the visualforce code

----Where the link is displayed

<apex:repeat value="{!lstUnitReport}" var="pUnitRep" >
<apex:commandlink style="font-size:13px;color:#black;white-space:nowrap;" rendered="{!AND(unitselectedval!=null,pUnitRep.Surl!=null)}"
onclick="execreport('{!pUnitRep.CR.Report_Name__c}');" immediate="true">
{!pUnitRep.CR.Report_Name__c}2<br/>
</apex:CommandLink>

</apex:repeat>

 

--Java script code

<apex:outputpanel id="jspanel">
<script type="text/javascript">
function execreport (param) {
dosetvariable('param');
alert('{!stringUrl}');
}
</script>
</apex:outputpanel>

 

--action function

<apex:actionfunction name="dosetvariable" action="{!setclassvariable}" rerender="jspanel" >
<apex:param name="param1" assignTo="{!sreportName}" value=""></apex:param>
</apex:actionfunction>

 

I can see through the debug log that the action function is calling the controller method "setclassVariable" but the alert in the java script is blank.  

 

Im not sure if there is a better way to handle this if there is please let me know.

Thanks in advanced.

bob_buzzardbob_buzzard

I think you have a race condition there - you are calling the action function but not waiting until it completes before outputting the stringURL.  What you need to do is have some conditionally rendered javascript that executes after the postback for the action function completes.

 

There's an example of this sort of thing on my blog at:

 

http://bobbuzzard.blogspot.co.uk/2011/05/refreshing-record-detail-from-embedded.html

 

its not an exact match with your scenario, but should be straightforward to adapt.

 

 

SRKSRK

try this i modify your JS a little and add on complite on action function

 

--Java script code

<apex:outputpanel id="jspanel">
<script type="text/javascript">
function execreport (param)

{
        dosetvariable('param');
}


function ShowFinalURL()
{
    alert('{!stringUrl}');
}


</script>


</apex:outputpanel>

 

--action function

<apex:actionfunction name="dosetvariable" action="{!setclassvariable}" rerender="jspanel" oncomplite="ShowFinalURL();">
<apex:param name="param1" assignTo="{!sreportName}" value=""></apex:param>
</apex:actionfunction>