Saturday, March 23, 2013

Eclipse Maven Build Fail - use -source 5 or higher to enable annotations

When you are using Maven package option in eclipse for generating a war file of a java web project which has the annotation in it,you will encounter the Build Fail error, below is the sample error which you will encounter, if the JRE and Annotation compiler wasn't configured properly in Eclipse
FAILED for project: 
C:\Documents and Settings\MRamanujam\workspace\ExpenseReporting\src\main\java\com\expense\domain\[9,2] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
To resolve the issue first you need to make sure that, Java compiler version you are using is greater than 5

javac -version

Next go to your project properties, select the Java Compiler in the tree menu.

Make sure the Compiler Compliance level is more than 1.5

Next click Annotation Processing and enable project specific settings, and apply the settings.

Then do the Maven package, your build will be successful, and the war wil be generated.

Happy Programming...!!!

Friday, March 1, 2013

Different ways of accessing a Zend View Helper

A Zend View Helper is simply a class, which follows a certain convention.When attached to a view object, you can call the helper as if it were a method of the view object itself. The View object retains helper instances,which means that they retain states between calls.
By convention we should use these view helpers in the View Layer only, but there are some circumstances we end up breaking this convention, start using these helpers in Controller, Helpers and Models. Lets see, how we can access the View Helpers from the differnt parts
//In Action Controller, you can access the view helper like below

//In Action Helper, you can access the view helper like below
$view = $this->getActionController()->view;

//Suppose if you are in the Model, where you don't have any 
//reference to Zend, this is how you have to access
$viewObject = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view;

Happy Programming ...!!!