0

JSF で Spring MVC を使用しようとしています。しかし、私は JSF をプレゼンテーション層として使用しています。私のJSFビューを表示するのは問題ではありません@Controller...しかし、を使用するh:formと、レンダラーは(ディスパッチャーなしで)間違ったURLを使用します。

ビューを取得するための正しい URL は次のとおりです (method=GET):
http://localhost:8080/AppName/dispatcher/testController/create

JSF ビュー フォームは、次の URL でレンダリングされます。
http://localhost:8080/AppName/WEB-INF/jsf/testController/create

フォームの正しい URL は (method=POST) です。
http://localhost:8080/AppName/dispatcher/testController/create

私のコントローラー:

@Controller
@RequestMapping(value = "/testController")
public final class TestController
{

  [...]

  @RequestMapping(value = "/create", method = RequestMethod.GET)
  public void getCreateNew(final Model model)
  {
    [...]
  }

  @RequestMapping(value = "/create", method = RequestMethod.POST)
  public void postCreateNew(final Model model)
  {
    [...]
  }
}

私の見解:

<?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"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:l="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
     >

    <h:head>
        <title>Create new</title>
    </h:head>
    <h:body>
        <h:messages errorClass="error"/> 

        <f:view>
            <h:form>
                <h:panelGrid columns="2" columnClasses="label, value" styleClass="grid">
                    <h:outputText value="${name}" />
                    <p:inputText label="Test: ${name}" required="true">
                        <f:validateLength minimum="3" />
                    </p:inputText>
                </h:panelGrid>
                <p:commandButton type="submit" value="${labelSubmit}" action="spring:@testController.doneCreateNew" />
            </h:form>
        </f:view>
    </h:body>
</html>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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-app_3_0.xsd">
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <listener>
        <listener-class>
            org.springframework.web.context.request.RequestContextListener
        </listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <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>dispatcher</servlet-name>
        <url-pattern>/dispatcher/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
</web-app>

顔-config.xml:

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.1"
    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_1.xsd">

    <application>
        <el-resolver>
            org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver>
    </application>

</faces-config>

ディスパッチャ servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsf/" p:suffix=".jsf" />

</beans>

そして、applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

    <mvc:annotation-driven />
    <context:annotation-config/>
    <context:component-scan base-package="com.sommer_engineering"/>

    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>

</beans>

なぜこれがうまくいかないのか誰にも分かりますか?どんなアイデアでも嬉しいです...

4

2 に答える 2

1

以下の編集を参照してください

この同じ問題を自分で解決しなければならなかったので、ここに回答を残しておきます。シンプルなpretty-configを介して書き換えルールを統合すると、うまくいきました。

  1. PrettyFacesの依存関係を追加し ます (注: PrettyFaces に慣れていない場合は、おそらくあなたが思っているものとは異なるでしょう)。

  2. 書き換えルールを追加する

ディスパッチャのサーブレット マッピングが次のようになっている場合:

    <servlet-mapping>
      <servlet-name>dispatcher</servlet-name>
      <url-pattern>/dispatcher/*</url-pattern>
    </servlet-mapping>

ビューリゾルバーには次のようなプロパティがあります。

    p:prefix="/WEB-INF/jsf/" p:suffix=".jsf"

次に、 pretty-config.xml は次のようになります。

     <pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
                  http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">

        <url-mapping id="pretty_spring_urls">
            <pattern value="/dispatcher/WEB-INF/jsf/{spring}.jsf" />
            <view-id value="/dispatcher/{spring}" />
        </url-mapping>

    </pretty-config>

編集: ただし、Prettyfaces は、組み込みのグラスフィッシュ サーバーでしか機能しませんでした。 Urlrewriteは、glassfish、Tomcat 7、および jboss で機能しました。

于 2013-09-07T15:57:11.467 に答える
0

これを試して、それをdispatcher-servlet.xmlに暗示することができます

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="" p:suffix=".jsf" />
于 2013-07-29T07:57:56.257 に答える