0
私はWebでグーグルの例で、非常に簡単なSpring 3 + JSF2.1の統合を試みています。アクションコントローラ自体JSF 2.1 Spring 3.0インテグレーション
<h:form>
<h:message for="textPanel" style="color:red;" />
<h:panelGrid columns="3" rows="5" id="textPanel">
//all my bean prperties mapped to HTML code.
</h:panelGrid>
<h:commandButton value="Submit" action="#{actionController.actionSubmitted}" />
</h:form>
今:
今@ManagedBean(name="actionController")
@SessionScoped
public class ActionController implements Serializable{
@ManagedProperty(value="#{user}")
User user;
@ManagedProperty(value="#{mailService}")
MailService mailService;
public void setMailService(MailService mailService) {
this.mailService = mailService;
}
public void setUser(User user) {
this.user = user;
}
private static final long serialVersionUID = 1L;
public ActionController() {}
public String actionSubmitted(){
System.out.println(user.getEmail());
mailService.sendUserMail(user);
return "success";
}
}
私の豆春
actionController.actionSubmittedに提出マイHTML()メソッド:だからここ
は私のコードです:
public interface MailService {
void sendUserMail(User user);
}
public class MailServiceImpl implements MailService{
@Override
public void sendUserMail(User user) {
System.out.println("Mail to "+user.getEmail()+" sent.");
}
}
これは
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
私のapplicationContext.xmlを
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="mailService" class="com.vanilla.jsf.services.MailServiceImpl">
</bean>
</beans>
私の顔-config.xmlには、次のようである私のweb.xmlです:
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
<message-bundle>
com.vanilla.jsf.validators.MyMessages
</message-bundle>
</application>
<managed-bean>
<managed-bean-name>actionController</managed-bean-name>
<managed-bean-class>com.vanilla.jsf.controllers.ActionController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>mailService</property-name>
<value>#{mailService}</value>
</managed-property>
</managed-bean>
<navigation-rule>
<from-view-id>index.xhtml</from-view-id>
<navigation-case>
<from-action>#{actionController.actionSubmitted}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>submitted.xhtml</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
私の問題は、私はということです私のmailService Spring beanがnullであるため、NullPointerExeptionを取得しています。
public String actionSubmitted(){
System.out.println(user.getEmail());
//mailService is null Getting NullPointerException
mailService.sendUserMail(user);
return "success";
}
こんにちは、サンプルのリンクを教えてください、私は同様の統合をしたいですか? –
@Jsword、問題ありません:http://www.mkyong.com/jsf2/jsf-2-0-spring-integration-example/ –
ゲッターが不在の場合、VariableResolverは 'プロパティ'を検出しません。 –