Domanda

I would like to development an simple application using the following envirnoment.

  1. JBoss 7.1.1
  2. JBoss Seam 2.3
  3. JSF 2.0
  4. Rifaces 4.0
  5. Spring 3.0
  6. JPA 2.0
  7. Eclipse IDE with JBoss Tool 3.2

Most of the configuration properly work. But I cannot inject the Spring Bean from Seam Action Bean. There is no error and exception when page is loaded. My Data table is

In web.xml,

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>jsf-seam</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.seam</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>org.richfaces.skin</param-name>
    <param-value>blueSky</param-value>
  </context-param>
  <listener>
    <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
  </listener>
  <filter>
    <filter-name>Seam Filter</filter-name>
    <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>Seam Filter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <servlet>
    <servlet-name>Seam Resource Servlet</servlet-name>
    <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Seam Resource Servlet</servlet-name>
    <url-pattern>/seam/resource/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>facelets.DEVELOPMENT</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
  </context-param>
  <security-constraint>
    <display-name>Restrict raw XHTML Documents</display-name>
    <web-resource-collection>
      <web-resource-name>XHTML</web-resource-name>
      <url-pattern>*.xhtml</url-pattern>
    </web-resource-collection>
    <auth-constraint/>
  </security-constraint>
</web-app>  

In 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">
    <application>
        <locale-config>
            <default-locale>en</default-locale>
        </locale-config>
    </application>
</faces-config>

In component.xml;

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.org/schema/seam/components"
            xmlns:core="http://jboss.org/schema/seam/core"
            xmlns:persistence="http://jboss.org/schema/seam/persistence"
            xmlns:drools="http://jboss.org/schema/seam/drools"
            xmlns:bpm="http://jboss.org/schema/seam/bpm"
            xmlns:security="http://jboss.org/schema/seam/security"
            xmlns:mail="http://jboss.org/schema/seam/mail"
            xmlns:web="http://jboss.org/schema/seam/web"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:spring="http://jboss.com/products/seam/spring"
            xsi:schemaLocation=
                "http://jboss.org/schema/seam/core http://jboss.org/schema/seam/core-2.3.xsd
                 http://jboss.org/schema/seam/persistence http://jboss.org/schema/seam/persistence-2.3.xsd
                 http://jboss.org/schema/seam/drools http://jboss.org/schema/seam/drools-2.3.xsd
                 http://jboss.org/schema/seam/bpm http://jboss.org/schema/seam/bpm-2.3.xsd
                 http://jboss.org/schema/seam/security http://jboss.org/schema/seam/security-2.3.xsd
                 http://jboss.org/schema/seam/mail http://jboss.org/schema/seam/mail-2.3.xsd
                 http://jboss.org/schema/seam/web http://jboss.org/schema/seam/web-2.3.xsd
                 http://jboss.org/schema/seam/components http://jboss.org/schema/seam/components-2.3.xsd">

   <core:init debug="true" jndi-pattern="@jndiPattern@"/>
   <spring:context-loader config-locations="classpath:spring-bean.xml"/>
   <core:manager concurrent-request-timeout="500"
                 conversation-timeout="120000"
                 conversation-id-parameter="cid"
                 parent-conversation-id-parameter="pid"/>

   <!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->
   <web:hot-deploy-filter url-pattern="*.seam"/>

   <!-- If you are still using JBoss 4, uncomment this to have your PU started -->
<!--   <persistence:entity-manager-factory name="entityManagerFactory"-->
<!--                      persistence-unit-name="jsf-seam"/>-->
   <!-- If you are still using JBoss 4, uncomment this to have the entityManagerFactory ysed -->
<!--   <persistence:managed-persistence-context name="entityManager" auto-create="true"-->
<!--                          entity-manager-factory="#{entityManagerFactory}"/>-->

   <persistence:managed-persistence-context name="entityManager" auto-create="true"
                           persistence-unit-jndi-name="java:/jsf-seamEntityManagerFactory"/>

   <drools:rule-base name="securityRules">
      <drools:rule-files><value>/security.drl</value></drools:rule-files>
   </drools:rule-base>

   <security:rule-based-permission-resolver security-rules="#{securityRules}"/>

   <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>

   <event type="org.jboss.seam.security.notLoggedIn">
      <action execute="#{redirect.captureCurrentView}"/>
   </event>
   <event type="org.jboss.seam.security.loginSuccessful">
      <action execute="#{redirect.returnToCapturedView}"/>
   </event>

   <mail:mail-session host="localhost" port="25"/>

   <!-- For use with jBPM pageflow or process management -->
   <!--
   <bpm:jbpm>
      <bpm:process-definitions></bpm:process-definitions>
      <bpm:pageflow-definitions></bpm:pageflow-definitions>
   </bpm:jbpm>
   -->

</components>

In my Seam Action Bean;

@Scope(CONVERSATION)
@Name("ManageDepartmentBean")
public class ManageDepartmentBean implements Serializable {
    private static final long serialVersionUID = -4373053763864526454L;

    @Out(value = "departmentList")
    public List<Department> departmentList;

        public List<Department> getDepartmentList() {
            return departmentList;
        }   

    @In("#{DepartmentService}")
    private IDepartmentService departmentService;

    @Begin
    public String begin() {
        departmentList = departmentService.findAllDepartments();
        return "success";
    }


    public String increment() {
        return "success";
    }


    @End
    public String end() {
        return "home";
    }
}

In my Spring bean;

@Service(value = "DepartmentService")
public class DepartmentService implements IDepartmentService{
    @Resource(name = "DepartmentDAO")
    private IDepartmentDAO departmentDAO;

    @Transactional(propagation = Propagation.REQUIRED)
    public List<Department> findAllDepartments() {
        return departmentDAO.findAll();
    }
}

I also try to used as below in web.xml, but it does not work.

  <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-beans.xml</param-value>
  </context-param>
  <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

in my page;

    <rich:dataTable value="#{ManageDepartmentBean.departmentList}" var="dep" id="departmentTable">
        <rich:column sortBy="#{dep.id}">
            <f:facet name="header">
                <h:outputText value="Department ID"/>
            </f:facet>
            <h:outputText value="#{dep.id}" />
        </rich:column>
        <rich:column sortBy="#{dep.name}">
            <f:facet name="header">
                <h:outputText value="Name"/>
            </f:facet>
            <h:outputText value="#{dep.name}" />
        </rich:column>
        <rich:column sortBy="#{dep.description}">
            <f:facet name="header">
                <h:outputText value="Description"/>
            </f:facet>
            <h:outputText value="#{dep.description}}" />
        </rich:column>
    </rich:dataTable>
È stato utile?

Soluzione

I get to inject spring bean from seam action bean using @In annotation. There is no need to do configuration for seam component into spring-bean.xml or applicationContext.xml.

In web.xml

 <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-beans.xml</param-value>
  </context-param>
  <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

In faces-config.xml

<application>
    <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>   
</application>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top