0

I have a VisualForce page that is made up of different components. One of my components is passed in a Case and displays the case fields.

If there is an edit to the case I would like to save it with associated controller to that component. If saving produces an error I would like to pass that error to the parent VisualForce page/controller and display the error message there.

Is it possible to communicate with other components/VisualForce pages? I am looking for something similar to an event in lightning components.

2

Controller Component Communication will be useful if you are having different visualforce components and you wanted to communicate with them.

You can find more details here:-
Ref:
Controller Component Communication

The first step is to create a virtual class that every controller that needs to communicate with a component controller will extend.

public with sharing virtual class PageControllerBase {
    
  private ComponentControllerBase myComponentController;
    
  public virtual ComponentControllerBase getMyComponentController() {
    return myComponentController;
  }

  public virtual void setComponentController(ComponentControllerBase compController) {
    myComponentController = compController;
  }
    
  public PageControllerBase getThis() {
    return this;
  }
    
}

Basically we are declaring a field compController to hold a reference to the component controller instance. We also set up a getter to return the instance of the page controller. Finally, we create a virtual method to set the compController. It is useful to make these virtual so that you can simply extend this class in your page controller and, if required, cast the component controller to a specific type (assuming that your component controller extends the class below). The next step is to create a virtual class for the ComponentController something like this:

public with sharing virtual class ComponentControllerBase {

  public PageControllerBase pageController { get; 
    set {
      if (value != null) {
    pageController = value;
    pageController.setComponentController(this);
      }
    }
  }
}

This class simply defines a property to contain the page controller. This value will be passed by using an attribute on the component markup. Again, these methods are defined as virtual in case you need special handling or casting for the page controller. Once you have created these two virtual classes you can now create component controllers and page controllers that extend these classes. This will imbue your controller implementations with the ability to communicate with each other.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.