Sunday, October 9, 2016

Maven cannot find richfaces 3.3.X artifact

As part of our technology upgrade, we just changed our deployment process to use Maven from Ant. As part of that while configuring the RichFaces 3.3.3.Final, i was getting artifact missing error in the pom.xml. When i looked into the details, it seems to that RichFaces related jar was not located in the central maven repository, it was maintained in the JBoss Maven repository. So you have to update your maven settings.xml to look into the JBoss Maven repository to download the jar and its dependencies.

There are two locations where a maven settings.xml file may live:

The directory where you have installed the maven: ${maven.home}/conf/settings.xml
The user specific directory: ${user.home}/.m2/settings.xml

If you haven't installed specifically the .m2 will not have setting.xml, in that case, what you have to do is copy the settings.xml into the user specific .m2 directory. And update the configuration details provided in the below link Maven to use JBoss Repository. After updating the settings, just update your project, the rich faces and its dependent jar will get downloaded from the JBoss Maven repository.

Happy Programming...!!!

Tuesday, July 19, 2016

java.lang.StackOverflowError at javax.servlet.http.HttpServletResponseWrapper.setStatus(

You may encounter this error while working on upgrading your project from JSF 1.* to 2.0. To err is human, we would have updated all our JAR files, refactored our code to use the latest features and annotations etc. But when you start your server, you will see the error, and it will go in the infinite loop. The issue is because of the we haven't update our faces-config.xml DOCTYPE to use latest version. It should be the in the old version. You have to change the version


 <faces-config xmlns=""  


 <faces-config xmlns=""  

Just change the xsd version as above, that's all.

Happy Programming...!!!

Sunday, May 8, 2016

java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be declared immediately after the model attribute

By default, Spring MVC throws an exception when errors occur during request binding. This usually not what we want – instead we should be presenting these errors to the user. We’re going to use a BindingResult by adding one as an argument to our controller method:

 @RequestMapping(value="/addEmployee", method=RequestMethod.POST)  
      public String addEmployees(BindingResult result, @ModelAttribute("employee") Employee employee,  
                Model model, final RedirectAttributes redirectAttributes){  

The BindingResult argument needs to be positioned right after our form backing object – it’s one of the rare cases where the order of the method arguments matters. Otherwise we’ll run into the following exception :

java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply:
public java.lang.String controller.EmployeeController.addEmployees(org.springframework.validation.BindingResult,entity.Employee,org.springframework.ui.Model,

To correct the above exception, just change order of the parameter, where your binding result parameter has to be just after the ModelAttribute as below

      @RequestMapping(value="/addEmployee", method=RequestMethod.POST)  
      public String addEmployees( @ModelAttribute("employee") Employee employee,  
                BindingResult result, Model model, final RedirectAttributes redirectAttributes){  

Happy Programming...!!!

Sunday, March 27, 2016

javax.servlet.ServletException: Circular view path []: would dispatch back to the current handler URL [/] again - Junit

While running a Standalone Junit Test for Spring Controller, sometimes you may incur the below exception, and your test will fail. This is because, when you don't declare or configure the ViewResolver in UnitTest, Spring registers a default InternalResourceViewResolver which creates instances of JstlView for rendering the View.

javax.servlet.ServletException: Circular view path [addExpense]: would dispatch back to the current handler URL [/addExpense] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
 at org.springframework.web.servlet.view.InternalResourceView.prepareForRendering(
 at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(
 at org.springframework.web.servlet.view.AbstractView.render(
 at org.springframework.web.servlet.DispatcherServlet.render(

To resolve the issue, we need to configure the ViewResolver, in the setup method of the Test class, Below is the sample code to do that. In the setup method, i have initialized the InternalResourceViewResolver, and assigned it to the viewResolver of standaloneSetup of MockMvcBuilder, this will resolve the issue.

public class ExpenseControllerTest {
    private ExpenseController expenseController;
    private MockMvc mockMvc;

    public void setup() {
 // Process mock annotations

        // Setup Spring test in standalone mode
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        this.mockMvc = MockMvcBuilders.standaloneSetup(expenseController).setViewResolvers(viewResolver).build();       

    public void testAddExpense() throws Exception{

Happy Programming.

Tuesday, March 15, 2016

Error: Could not find or load main class - Eclipse

When your eclipse project libraries are not pointing to JDK, and instead it is pointing to the JRE, you will get this error "Error: Could not find or load main class". If the JDK path was not configured in your installed JRE's please do the following.

From Eclipse Click File > Properties, select Java Build Path and select Libraries Tab.
In the Libraries Tab, select the JRE system library and click Edit, which will pop up a window.

Then click Installed JREs, button, which will pop up a window, which will display the JRE installed, as below.

Now Click Add, and provide the path, where your java jdk have been installed. In the below image, i have configured the path, where my Java JDK has been installed. Once set the path, it will fetch all the JRE libraries under that folder, as shown below.

Once you clicked finish button, the JDK entry will be shown in the Installed JREs window. Now select the newly added path and click apply. Now in the JRE System library window, Click on the Alternate JRE dropdown, it will list the jdk which was added by us, select that and click finish. This will change your JRE System library point to the JDK, what we have installed. Now select the xsd file and generate the JAXB classes, it will generate the classes successfully without any error.

Happy Programming.