Creating Spring Boot MVC application with AWS DynamoDB in 10 mins

Image
AWS DynamoDB DB is a serverless NOSQL database. You can understand how to build a spring boot Java web MVC application (Game Leaderboard) reading a AWS DynamoDB in 10 mins. Source of the demo code: https://github.com/babysteps-topro/spring-mvc-dynamodb Command to run the project: mvn spring-boot:run Video explain the table design: https://youtu.be/V0GtrBfY7XM Prerequisite: Install the AWS CLI: https://youtu.be/pE-Q_4YXlR0 Video explain the how to create the table: https://youtu.be/sBZIVLlmpxY

Injecting Guice managed object into JSF View Scoped bean

In previous post, I demonstrate how to integrate JSF with Guice and MyBatis. However, my friend experiences some problem when he is using view scoped backing bean.
He found that he cannot re-inject the service class after serialization. I have done some tricks to solve this problem.This is simply done by overriding the readObject() and writeObject() method.

The BasePageBean in the previous post is changed as follow:

BasePageBean.java
package org.borislam.view;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.faces.context.FacesContext;
import javax.faces.context.Flash;
import javax.servlet.ServletContext;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.ppstation.PpContext;

public abstract class BasePageBean  implements Serializable{

   private transient Injector injector;
   
   
   public BasePageBean() {}
   
   public Injector getInjector() {
     if(injector == null) {
       ServletContext servletContext = (ServletContext)FacesContext.getCurrentInstance().
                                        getExternalContext().getContext();
       injector = (Injector)servletContext.getAttribute(Injector.class.getName());  
     }
     return injector;
   }
   public void setInjector(Injector injector) {
     this.injector = injector;
   }
   
   @PostConstruct
   public void init() {
     getInjector().injectMembers(this);
   }
   
   private void writeObject(ObjectOutputStream stream) throws IOException {
      stream.defaultWriteObject();
      System.out.println("write object...");
   }

   private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
      stream.defaultReadObject();
      getInjector().injectMembers(this);
      System.out.println("read object...");
   }
   
   
   public  Flash flashScope (){
   return (FacesContext.getCurrentInstance().getExternalContext().getFlash());
   }


   
}      

Comments

Popular posts from this blog

Sample Apps: Spring data MongoDB and JSF Integration tutorial (PART 1)

Writing your spring security expression language annotation - PART 1

Customizing Spring Data JPA Repository