Menu

AEM Sling Models

What is the Sling Models?

While working with Sling in Adobe Experience Manager[AEM]; we need to map our objects (Java backend object) with  Apache Sling resource. Many Sling projects want to be able to create model objects - POJOs which are automatically mapped from Sling objects, typically resources, but also request objects. With the help of sling models, we can define a model object "a Java class or interface" and map that object with sling resources. Before sling models, we are achieving these all using WCMUse and WCMUsePojo which are quite similar to sling models.

To use the Sling Models in your project first you need to add the following dependency in your pom.xml file.
<dependency>
   <groupId>org.apache.sling</groupId>
   <artifactId>org.apache.sling.model.api</artifactId>
   <version>1.3.0</version>
   <scope>provided</scope>
<dependency>

@Model annotation 

To map a java class or interface with sling resource we use @Model annotation and could pass an adaptables parameter into it to make a class adaptable by sling model.

@Model(adaptables = Resource.class)
public class RashidJorvee {
 //Write your code here
}  
 or
@Model(adaptables = SlingHttpServletRequest.class)
public class RashidJorvee {
 //Write your code here
} 

@Inject annotation

Using @Inject we can make a filed and method injectable. We can also inject a constructor using @Inject annotation. We also use @Inject with @Filter option to pass the reference to an available OSGi service, which works similarly as @Refernce.
@Inject
private String firstName;
@Inject
String getName();
There are many other options we have which makes injection make accurate and exact. like following

@Named

To match the name of the property with field name

@Via

Change the adaptable object instead of using the original adaptable object

@Default 

To assign a defult value to any field or property.

@Filter

Filter an OSGi service

@Optional

Mark filed and method injection optional.

@Source

To manage the ambiguity between injector, it helps us to tie the injected field or method to a particular injector. 

@PostConstruct annotation

Using PostConstruct annotation we can invoke any method which we want to execute when all injection has been completed for that class. This is act as similar to the activate() method which we use for WCMUsePojo or WCMUse.

@PostConstruct
public void letMeExecuteFirst() {
 //Write your code here;
}


Public provident fund (PPF)

Public provident fund(PPF) is the safest investment available in the market for long time investment at least more than 7 years. Actual maturity of PPF is for 15 years and a person cannot withdraw his/her money completely before 15 years, but they can withdraw some amount partially after seven years from the opening of the account.
PPF gives the highest rate of interest in any investment, and RoI is always same with PF and VPF account, as these all are the investment plan from the government of India.

Why you should invest in PPF?

  • Your money will safe in hand of Govt.
  • PPF account is actually managed by India post(post office).
  • A high rate of interest.
  • Tax exemption under 80 C.
  • Interest earned on PPF amount in non-taxable
  • You can open your account at any time with minimum/subscription amount of 500 rupees.
  • Within a financial year you maximum you could submit 150,000 rupees.
  • Funds can be deposited to PPF account, only 12 times in a Financial Year.
  • Premature closure is not allowed before 15 years, but you could partially withdraw after seven years.
  • You can take a loan on this account after the 3rd financial year.

Where to open a PPF account?

PPF is a saving and tax saving scheme of GoI and managed by the post office of India. You could open PPF account with any post office or with any public or private banks.

for more details and current benefits of scheme you could visit Post-Office-Saving-Schemes | indiapost.gov.in

Eclipse shortcuts for Java programming

When you are working with Eclipse IDE to write the java programs, we have too many shortcuts to write the statements in java which Eclipse supports. using these shortcuts you could write your program easy and fast. 
Here I am writing few shortcuts to write java program in Eclipse IDE. Go and try these shortcuts and let us know you have other shortcuts to write and make efficient programming.

Shortcuts commands:

  1. ALT + CTRL + A: to edit and write multiple lines simultaneously  
  2. ALT + Shift + J: Add code Definition
  3. Select a line then ALT + Arrow (Up/Down): to move the code up and down
  4. Shift + Alt + I: to align the code
  5. Shift + mouse hover: to see the method implementation code.
  6. CTRL + O: to see the list of all variables and methods.
  7. CTRL + K: to find matching text within the file.
  8. CTRL + Click on a method name to open the implementation of the method.
  9. Ctrl + space: to open the preference window or template proposal.
  10. You can directly copy and paste your complete code from notepad to eclipse SCR folder, and eclipse will automatically create package and class for that class and paste your code into it. Open notepad > Copy all code from pad > open eclipse > right click on src folder in case if you don't have src folder then right click on project name > select the paste option 
  11. Inline and split variables: select variable then CTRL + 1 and select the option
  12. CTRL + 2, L to assign the value into a local variable
  13. ALT + Shift + M: Select single or multiple lines and move those selected codes in a new method.
  14. Ctrl + Alt-J: to Join more than one lines in a single line
  15. syserr or sysout: to write the complete System.err.println() or  System.out.println() respectively.
  16. Type a string literal "rashid"; select the literal "rashid", then press Ctrl + space, now type sysout/syserr to to pass that string in the argument.


If you face any issue in using these shortcuts then please let us know, we will help you to understand these shorthands.