Nov 27, 2016

Sujesh Ramachandran

Refresh component or sections in Lightning component




In the last blog, I have discussed about the advantages of using Inheritance in lightning component (Link). Probably this topic is a bit small technique to just refresh a component rendering section in a lightning component.

Here I am creating 2 components:
1) ComponentContainer.cmp - which will call the Refresh component.
2) RefreshComponent.cmp - Component gets refreshed every time on click of a button on containing component(component 1).

ComponentContainer.cmp has an attribute refreshFlag, which will be set true/false on Refresh button click based on the existing value. The same variable is used in the aura:if to render either the true/false case. Also passing a attribute RefreshCount to just show the effect of refresh in the RefreshComponent.




Here is the output:



Follow me @ramsujesh

Read More

Nov 19, 2016

Sujesh Ramachandran

Inheritance in Lightning Component




I have been thinking about to write on Inheritance in lightning component and thought it is a simple topic to script as a blog. But I did not see a blog wherein the Inheritance is well written, so here I am trying to explain in details, please let me know in case of any suggestion. 

Here I am going to talk about:
  • How can a component inherit from a parent component?
  • How will be the attributes behaviour in child  and parent component?
  • How will be the event behaviour in parent and child component?
  • How the methods in the helper, controller JS of parent and child component behaves?
  • What are other benefits of Inheriting a parent component in Lightning?

Before jumping into the discussion, I just want to talk about the child and parent component we are going to build as part of the above explanation. We are going to create a generic parent component to display a form to capture any details. Child component will inherit parent component to show form  specific to capture personal details without re-writing the code.

Create a Parent Component

Object Details component should have an attribute extensible=”true” so that any component having access can inherit from ObjectDetails component.



Child Component and Attribute Behaviour

Now the child component, here we are going to just inherit from parent component and pass only the relevant attribute values so that the same attribute values in parent will be overridden. For more details below is the code of child component. 

All Helper Methods, Controller Methods of parent component will be accessible to child component, For example, if the parent component controller JS has an action called doSomething, the child component can directly call the action using the {!c.doSomething} syntax. Similarly Child Component controller can call Helper methods available in Parent component. Salesforce don't recommend using inheritance of client-side controllers as this feature may be deprecated in the future to preserve better component encapsulation., so salesforce recommend that you put common code in a helper instead.

A child component can override a parent component's helper method by defining a method with the same name as an inherited method in the child component helper JS. In this way you don’t really have to rewrite the code for every object, for any object just pass the attribute values. 

Events Behavior and Order of Execution

A child component that extends a parent component can handle events fired by the parent component. The child component automatically inherits the event handlers from the parent component.
The parent and child component can handle the same event in different ways by adding an <aura:handler> tag to the child component. The framework doesn't guarantee the order of event handling.

Finally I just added the PersonalDetailsForm.Cmp under a Tab in Account Details Page using App Builder and below is the output:



Let me know in case of any suggestions/feedback.

Follow me @ramsujesh
Read More

May 11, 2014

Sujesh Ramachandran

Drag and Drop in Visualforce using jQuery



It was my long time wish to start blogging and kept on hold for a while, so just starting with a piece of code written some time back. Drag and Drop in Visualforce which will help us to create asynchronous rich UI. 



Just started posting technical topics and will meet you all with interesting topics going forward.

Thanks,
Sujesh
Follow me @ramsujesh

Read More