Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Thanks to this you can make your code even cleaner. Check the following code snippets and see how Report

Code Block
languagejava
collapsetrue
// Now - with @Follow annotation
@SliceResource
public class ReportComponent  {
    @Follow
	@JcrProperty(value = "reportPath") 
	private ReportModel report; // this will build ReportModel based on resource path
                                // kept in reportPath property of current resource
	
	public String getReportValue() {
        return report.getValue();
    }
}
// Before
@SliceResource
public class ReportComponent implements InitializableModel {   
    @JcrProperty 
    private String reportPath;
    
    private ReportModel report;
    
    private ModelProvider modelProvider;
    
    @Inject
    public ReportComponent(ModelProvider modelProvider) {
        this.modelProvider = modelProvider
    }
    
    @Override
    public void afterCreated() {
        report = modelProvider.get(ReportModel.class, reportPath);
    }
    
    public String getReportValue() {
        return report.getValue();
    }
}

...