Show TOC

Procedure documentationImplementing the Managed Bean Locate this document in the navigation structure

 

This procedure describes how to implement the managed bean of the application Web development component app_web. For example, it stores logic such as methods for finding and storing entity instances, also methods for navigating between the available JSPs, and so on.

Procedure

  1. Open for editing the ProjectMB under app_web/Java_Resources:resource/com.sap.nwce.ra.edm.managedbean.

  2. Using EJB 3.0 annotation, inject the Project Facade EJB.

    Syntax Syntax

    1. @EJB
      private ProjectFacadeLocal projectFacade;
      
    End of the code.
  3. Add the following properties (including setters and getters)

    • Search patterns:

      Syntax Syntax

      1. private String projectsPtrn = "";
        	private String employeesPtrn = "";
        
      End of the code.
    • Currently selected entities:

      Syntax Syntax

      1. private Project currentProject = new Project();
        	private Employee currentEmployee = new Employee();
        
      End of the code.
  4. Add the following property (getter method only) for project employees.

    Syntax Syntax

    1. private HashMap<Integer, Employee> tempCurrProjEmplMap = new HashMap<Integer, Employee>();
      
      	public List<Employee> getTempCurrProjEmployees() {
      		return new ArrayList<Employee>(tempCurrProjEmplMap.values());
      	}
      
    End of the code.
  5. Add methods for finding and storing Project and Employee entity instances, and methods for navigating between the JSPs. Here is an example of such a method:

    Syntax Syntax

    1. public String navigationNewEmployee() {
      		currentEmployee = new Employee();
      		return "newEmployee";
      	}
      
    End of the code.
  6. Add methods for navigation to editProject and editEmployee. These methods have to read as a parameter current ID. Here is an example:

    Syntax Syntax

    1. private String obtainJSFParam(String param) {
      	String emplId = null;
      	FacesContext context = FacesContext.getCurrentInstance();
      	Map<String, String[]> paramsMap = context.getExternalContext()
      		.getRequestParameterValuesMap();
      	if (paramsMap.containsKey(param)) {
      		emplId = paramsMap.get(param)[0];
      	}
      	return emplId;
      }
      
      
      public String editEmloyee() {
      	String param = "emplId";
      	String emplId = obtainJSFParam(param);
      	currentEmployee = projectFacade.getEmployeeById(Integer.parseInt(emplId));
      
      	return "editEmployee";
      }
      
    End of the code.
  7. Enter the full source code of the ProjectMB.