2

I have one Visualforce page and one Visualforce controller. I have different attributes defined in the controller of Visualforce page as shown below

 public boolean firstPanel{get;set;}
 public boolean secondPanel{get;set;}
 public boolean thirdPanel{get;set;}

I also have a separate controller for Visualforce component which is being called inside in visualforce page and i am passing certain list of object in visualforce component from visualforce page. I have a function in the controller of Visualforce component which is being called when certain sets of operation is required.

Now i want when these operations are being called then attributes(firstPanel,secondPanel,thirdPanel) defined in the parent controller should be set in the component controller without redirecting. How can i accomplish this?

0

1 Answer 1

2

One way is to pass a reference of the page controller into the component like this.

The component has an attribute defined:

<apex:component controller="ComponentController">
    <apex:attribute name="pc" type="PageController" description=""/>
    ...
</apex>

The page sets a value in that attribute via a controller property:

<c:component pc="{!controller}" .../>

The page controller property is this:

public PageController controller {
    get {
        return this;
    }
}

Then your component markup can reference the page controller properties via {pc}. For example {!pc.firstPanel}.

5
  • How can i set the value of firstPanel which is the attribute of pagecontroller in component controller in APEX Class? Commented Sep 14, 2019 at 14:03
  • @Sheheri My bad I misunderstood your question. I don't have an answer to that. Commented Sep 14, 2019 at 14:10
  • @KeithC, found a post of yours addressing similar problem : salesforce.stackexchange.com/questions/220858/… .@Sheheri check this Commented Sep 15, 2019 at 0:48
  • @Arabinda i dont have controller extensions in my solution. I only have one visualforce page and two visualforce component and 3 apex controllers for each visualforce page and visualforce controller. Visualforce components are included in Visualforce page. There are some logic performed on each visualforce component on the basis of which i need to decide, if i have to show the other visualforce component or not.To show the other component boolean variable has been declared in controller of Visualforce page but i dont have any way on how to access that from componenet controller. Commented Sep 15, 2019 at 8:47
  • @MuhammadSheheryarAfsar, that case I can suggest you to use cookies to store some temp variables and manipulate based on your requirement. Give a try for this cookies approach. As in your case, extensions are not linked so this approach can help. Commented Sep 16, 2019 at 0:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.