Creating the empbean.java file – HP Integrity NonStop J-Series User Manual
Page 288

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
section.
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
section.
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;
import com.hp.empinfo.web.ServiceFinder;
public class EmpBean {
private int empid;
private String firstname;
private String lastname;
private int age;
private String email;
private String rord;
boolean exist = false;
boolean state = false;
288 Integrating Frameworks