You need to sign in to do that
Don't have an account?
LB_DD
Different controllers to VF page and RemoteAction, is possible?
Hello,
Have a VF page associated to a controller and want use another controller to receive @RemoteAction calls, is possible?
Example:
Visuaforce page
<apex:page standardStylesheets="false" docType="html-5.0" sidebar="false" showHeader="false" contentType="text/html" cache="true" controller="test_ControllerRA"> <h1>Congratulations</h1> This is your new Page <hr /> <p><a href="#" onclick="showMessage();">Press Me</a></p> <div id="zoneShowMsg">zone to show message</div> <script> function showMessage() { var str = 'name=TheName&info=Info+Tag'; document.getElementById('zoneShowMsg').innerHTML = 'Processing... please wait.'; try{ test_ControllerGlobalRA.processRA(str , function(Result, event) { console.log('Result:',Result); console.log('event',event); if (event.status) { console.log('Result=',Result); if(Result!= '') { document.getElementById('zoneShowMsg').innerHTML = 'Information:'+Result; } else { document.getElementById('zoneShowMsg').innerHTML = 'Problems with information:'+Result; } } }, {escape:true}); }catch(ex){ document.getElementById('zoneShowMsg').innerHTML = 'ERROR:'+ex; } } </script> </apex:page>
The VF Page Controller:
public with sharing class test_ControllerRA { public String getTheString(String str){ String[] arrStr = str.split('&'); String theText = 'Name: '+arrStr[0]+' / '; theText +='Info: '+arrStr[1]+' /// (finished)'; return theText; } }
The @RemoteAction controller:
global class test_ControllerGlobalRA{ @RemoteAction global static String processRA(string Str){ test_ControllerRA tcra = new test_ControllerRA(); String theStr = tcra.getTheString(Str); return theStr; } }
I want to use the VF page inside a iframe.
If anyone can help me, I thank.
Best Regards,
LB
Hi,
Add the extension attribute in apex page
Try the below modified code snippet
<apex:page standardStylesheets="false" docType="html-5.0" contentType="text/html" cache="true" controller="test_ControllerRA" extensions="test_ControllerGlobalRA">
<h1>Congratulations</h1>
This is your new Page
<hr />
<p><a href="#" onclick="showMessage();">Press Me</a></p>
<div id="zoneShowMsg">zone to show message</div>
<script>
function showMessage()
{
var str = 'name=TheName&info=Info+Tag';
document.getElementById('zoneShowMsg').innerHTML = 'Processing... please wait.';
try{
test_ControllerGlobalRA.processRA(str , function(Result, event)
{
if (event.status)
{
console.log('Result=',Result);
if(Result!= '')
{
document.getElementById('zoneShowMsg').innerHTML = 'Information:'+Result;
}
else
{
document.getElementById('zoneShowMsg').innerHTML = 'Problems with information:'+Result;
}
}
}, {escape:true});
}catch(ex){
document.getElementById('zoneShowMsg').innerHTML = 'ERROR:'+ex;
}
}
</script>
</apex:page>
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi,
Add the extension attribute in apex page
Try the below modified code snippet
<apex:page standardStylesheets="false" docType="html-5.0" contentType="text/html" cache="true" controller="test_ControllerRA" extensions="test_ControllerGlobalRA">
<h1>Congratulations</h1>
This is your new Page
<hr />
<p><a href="#" onclick="showMessage();">Press Me</a></p>
<div id="zoneShowMsg">zone to show message</div>
<script>
function showMessage()
{
var str = 'name=TheName&info=Info+Tag';
document.getElementById('zoneShowMsg').innerHTML = 'Processing... please wait.';
try{
test_ControllerGlobalRA.processRA(str , function(Result, event)
{
if (event.status)
{
console.log('Result=',Result);
if(Result!= '')
{
document.getElementById('zoneShowMsg').innerHTML = 'Information:'+Result;
}
else
{
document.getElementById('zoneShowMsg').innerHTML = 'Problems with information:'+Result;
}
}
}, {escape:true});
}catch(ex){
document.getElementById('zoneShowMsg').innerHTML = 'ERROR:'+ex;
}
}
</script>
</apex:page>
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hello Navatar_DbSup,
Thanks a lot, works :)
To all users with same problem, I post the final code to testing:
Visualforce Page:
The VF PageController:
The @RemoteAction Controller:
Best Regards,
LB