function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aakanksha SinghAakanksha Singh 

Passing values from vf page to lightning component through a shared controller

Hello everyone,
Is there any way to pass the value of an input text field in the vf page to lightning component, through a shared controller??

Thank You
Aakanksha Singh
_Zach Boyd_Zach Boyd
One option would be to dispatch a lightning event with the text field value from the Visualforce page to the lightning component. I have included a link to a blog post that shows how you can fire events from visualforce and handle within lightning.

http://cloudyworlds.blogspot.com/2016/02/lightning-events-via-visualforce.html
Aakanksha SinghAakanksha Singh
Hello Zach,
Thanks fo answering, but I don't have to use app, in my case lightning component itself is a tab.
Thanks once again
_Zach Boyd_Zach Boyd
Could you explain a little more on how you have it setup? In my original response I thought you had a lightning page with a visualforce component on the page. It should help me give a recommended approach. 
Aakanksha SinghAakanksha Singh
Well, its like thats my setup, but i'm not using lightning application, its just the component. I'm sharing the code.
<pre><!--Lightning Component--><aura:component controller="recieveVal">
    <aura:attribute name="vfVal" type="String" default=""/>
    <aura:attribute name="ifmsrc" type="String" default=""/>
    <aura:handler name="init" value="{!this}" action="{!c.myAction}"/>
    {!v.vfVal}
    <ui:button press="{!c.getValue}">Get Value</ui:button><br/><br/>
    <iframe id="myFrame" style="border: 1px solid" src="{!v.ifmsrc}" />
</aura:component></pre>

<pre>//component controller
({
    myAction : function(component, event, helper) {
        component.set("v.ifmsrc", 'https://wk-aakanksha-dev-ed.lightning.force.com/apex/recieveVal');
    },
    getValue : function(component, event, helper) {
        var action = component.get("c.getVfVal");
        action.setCallback(this,function(a){
            var state = action.getState();
            if(state=="SUCCESS"){
                component.set("v.vfVal",a.getReturnValue());                
            }            
        });
        $A.enqueueAction(action);
         var d = new Date();
         var n = d.getTime();  
         component.set("v.ifmsrc", 'https://wk-aakanksha-dev-ed.lightning.force.com/apex/recieveVal?t='+ n+'&var='+val );
    }
})</pre>

<pre>//Apex Controller
public with sharing class recieveVal {
    public static string VfPageVar{get; set;}
    public static void sendValue(){
        if(str != VfPageVar){
            str = VfPageVar;
        }
    }
    
    private static string str;
    
    @AuraEnabled 
    public static string getVfVal(){
        showData.sendValue();
        return str;
    }
}</pre>

<pre><!--Vf page-->
<apex:page controller="recieveVal" showHeader="false" standardStylesheets="false">
    <apex:form id="theform">
            <apex:inputText value="{!VfPageVar}">
                <apex:actionSupport event="onchange" action ="{!sendValue}"/>
            </apex:inputText>
            page variable:
            <apex:outputText value="{!VfPageVar}" id="VfPage"/>
    </apex:form>
</apex:page></pre>
sfdcMonkey.comsfdcMonkey.com
hi
i have a one question what is  showData.sendValue(); (line number14 on apex class) ?
Thanks
Aakanksha SinghAakanksha Singh
I'm sorry.. its not showdata, its recieveVal the class name.