beautypg.com

Creating the servicefinder.java file, Creating the empbean.java file, Creating the servicefinder.java file creating the – HP Integrity NonStop H-Series User Manual

Page 445: Empbean.java, File, Creating the

background image

}

Creating the

ServiceFinder.java

File

The

ServiceFinder.java

file is a Business Services class that contains the code to interact

with the data tier. The ServiceFinder service is used to get the Spring managed beans from

WebApplicationContext

.

To create the

ServiceFinder.java

file in the

com.hp.empinfo.web

package, complete the

following steps:

1.

Create the

ServiceFinder.java

file under the

com.hp.empinfo.web

package, as

explained in the

Creating the Controller for EmpInfo

section in the

Getting Started with

Spring

chapter.

2.

Modify the

ServiceFinder.java

file to integrate the MyFaces views with the Spring

business logic tier.

After modification, the

ServiceFinder.java

file must appear as shown:

package com.hp.empinfo.web;

import javax.faces.context.FacesContext;

import org.springframework.context.ApplicationContext;

import org.springframework.web.jsf.FacesContextUtils;

public class ServiceFinder {

public static Object findBean(String beanName) {
FacesContext context = FacesContext.getCurrentInstance();

ApplicationContext appContext = FacesContextUtils
.getWebApplicationContext(context);

Object o = appContext.getBean(beanName);

return o;

}

}

Creating the

EmpBean.java

File

The

EmpBean.java

file is used as a bean class for the view pages. This bean contains all the

properties related to the fields in the view pages and their setter and getter method.

To create the

EmpBean.java

file in the

com.hp.empinfo.web

package, complete the following

steps:

1.

Create the

EmpBean.java

file under the

com.hp.empinfo.web

package, as explained in

the

Creating the Controller for EmpInfo

section in

Getting Started with Spring

chapter.

2.

Modify the

EmpBean.java

file to contain the properties for the fields in the view.

After modification, the

EmpBean.java

file must appear as shown:

package com.hp.empinfo.web;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import com.hp.empinfo.service.IEmployeeDao;

Example of Integrating MyFaces into Spring

445

This manual is related to the following products: