1.) Create two maven projects (web, ejb - has HelloBean class) 2.)
2.) In the spider web purpose nosotros require to exercise three critical files within /WEB-INF folder:
beans.xml
<?xml version="1.0" encoding="UTF-8"?> <beans></beans>faces-config.xml
<?xml version='1.0' encoding='UTF-8'?> <faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version="2.0"> </faces-config>web.xml
Then our xhtml page, let's advert it home.xhtmlXXX - Merchant Gateway javax.faces.PROJECT_STAGE Development home.xhtml javax.faces.DEFAULT_SUFFIX .xhtml javax.faces.application.CONFIG_FILES /WEB-INF/faces-config.xml Faces Servlet javax.faces.webapp.FacesServlet 1 Faces Servlet /faces/* Faces Servlet *.jsf Faces Servlet *.faces Faces Servlet *.xhtml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> <h:body> <h:outputLabel value="#{helloBean.name}" /> </h:body> </html>
3.) For the instant purpose (ejb), nosotros volition exercise four files: 1 coffee degree too three xml. Inside resources/META-INF, nosotros require to create(beans.xml, ejb-jar.xml, sun-ejb-jar.xml)
beans.xml
<?xml version="1.0" encoding="UTF-8"?> <beans></beans>
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1"> <module-name>XXX-cg-ejbs</module-name> <display-name>YYY Gateway</display-name> </ejb-jar>
sun-ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd"> <sun-ejb-jar> <enterprise-beans /> </sun-ejb-jar>
And last, our degree file HelloBean.java
import javax.annotation.PostConstruct; import javax.ejb.Stateless; import javax.inject.Named; /** * @author Edward P. Legaspi * @since Jun 5, 2012 */ @Stateless @Named("helloBean") world degree HelloBean { someone String name; world HelloBean() { advert = "edward"; } @PostConstruct world void init() { advert = "edward"; } world String getName() { supply name; } world void setName(String name) { this.name = name; } }
*You should accept authorities annotation that beans.xml, should live created on both the spider web too ejb project. After that the JSF forepart should live able to telephone shout upward the ejb back.
0 komentar:
Please comment if there are any that need to be asked.