0

Spring と ICEFaces に基づくソフトウェアを開発しています。
にファイルがあり<project directory>/src/main/webapp/WEB-INF/views/<filename>.xhtml、次の URL を使用して正しくアクセスできます。http://<hostname>/<projectname>/<filename>.xhtml

ファイルには、<h:form id="formId">としてレンダリングされる が含まれています<form action="/<projectname>/WEB-INF/views/<filename>.xhtml" [.. some other stuff ..]>

これは、フォームに含まれる入力送信をクリックすると、ブラウザーが URL を開こうhttp://<hostname>/<projectname>/WEB-INF/views/<filename>.xhtmlとし、タイトルで述べたように、エラー 404 ページが表示されることを意味します。

ファイル .xhtml にも「長い」URL を使用して到達できるようにしたいと思います。構成エラーのために、現在それを達成できないと確信しています。

これは私のweb.xmlです:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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_2_5.xsd"
  version="2.5">

<web-app>
    <display-name>SIGLO</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

これは、前のファイルで参照されて いるapplicationContext.xmlです。

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

    <context:component-scan base-package="com.infoone.siglo" />
    <!--
         map all requests to /resources/** to the container default servlet 
        (ie, don't let Spring handle them)
    -->
    <bean id="defaultServletHttpRequestHandler" class="org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler" />
    <bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
        <property name="urlMap" >
            <map>
                <entry key="/resources/**" value-ref="defaultServletHttpRequestHandler" />
            </map>
        </property>
    </bean>
    <bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />
    <mvc:annotation-driven />

    <!-- JSF for representation layer. All JSF files under /WEB-INF/views directory -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" >
        <property name="cache" value="false" />
        <property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean name="icefacesResourceHandler" class="org.springframework.faces.webflow.JsfResourceRequestHandler" />

    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <property name="order" value="0" />
      <property name="mappings">
        <value>
          /javax.faces.resource/**=icefacesResourceHandler
        </value>
      </property>
    </bean>
    </beans>

最後に、これは私のfaces-config.xmlです:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.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-facesconfig_2_0.xsd">
    <application>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
        <locale-config></locale-config>
        <resource-bundle>
            <base-name>MessageResources</base-name>
            <var>msg</var>
        </resource-bundle>
    </application>
</faces-config>

この構成では、短いURLを正常に開くことができないことを指摘しておきます。実際、適切なコントローラーを作成するか、@Controller内に適切な@RequestMappingを作成する必要があります。

@RequestMapping(value = "<filename>", method = RequestMethod.GET)
public String creaBlocco()
{
    return "<filename>";
}

@RequestMapping(value = "<filename>", method = RequestMethod.POST)
public String creaBlocco([.. parameters ..]) {
    [.. stuff ..]
    return "<filename>";
}

はい、@RequestMappingの値は"<filename>".xhtml拡張子なしです。試行錯誤によって、GET を成功させるにはそのようなマッピングが必要であることを確認しました。一方で、そのような構成は本当にもろいものだと実感しています。より長いURL<filename>.xhtmlを使用してアクセスできるようにするには、構成ファイルで何を変更する必要がありますか?

ご清聴ありがとうございました。

4

1 に答える 1

1

いくつかの調査の結果、私はそれらのテクノロジーを本来の使用方法で使用していないという結論に達しました。同じコンテキスト内で同じ問題に直面している場合は、おそらく同じエラーが発生しているため、アプリケーションアーキテクチャを少し変更して解決する必要があります。実際、JSF /ICEFacesとSpringMVCをSpringWebFlowと 組み合わせて使用​​することが、最も快適で簡単なアプローチのようです。

その理由を説明しようと思います。
あなたのサイト/ユーザーのホームページは、彼/彼女の特権でアクティブ化できるユースケース(または、より良いのはフロー)へのリンクでいっぱいです。それらのリンクは次のようになりhttp://<page-url>?<flow-id>ます。Spring WebFlowのフローは、xmlファイル内の状態のグラフとして定義されます。状態間の遷移は、文字列、名前付きアクション、または条件によってラベル付けされます。一部の状態はビューステートです。つまり、このような状態に達したときにユーザーに表示するものがあります。したがって、という名前のビューステートごとに、<state-id>という名前の.xhtmlファイルが存在する必要があります<state-id>.xhtml

JSFとICEFacesによって提供されるボタンは常にとしてレンダリングされ<input type="submit" [..]>、含まれるフォームのアクションは常に含まれるページと同じURLを指します(つまりhttp://<page-url>?<flow-id>)。あれは事実です。
違いは、この場合、そのようなURLは(私の質問のように)実際のファイルによって裏付けられていないことですが、アプリが適切に構成されている場合、フローハンドラーは、で定義されているすべての状態と遷移に応答して管理しますxmlファイル、表示する適切なビューを選択します。

そのほか、JSFとICEFacesが提供するボタンにはアクション属性があります。ご想像のとおり、これらはフロー定義ファイルで定義されたアクションに対応します。したがって、action属性の特定の値を持つボタンをクリックすると、その文字列で正確にラベル付けされた現在の状態からの遷移がトリガーされます。
より具体的に言えば、ボタンをクリックすると、ブラウザはPOSTリクエストを送信します。POSTリクエストhttp://<page-url>?<flow-id>の本文には必要なすべてのパラメータが含まれています。フローハンドラーはそのPOSTリクエストを受信し、次の状態を計算して、ユーザーに表示する必要のあるビューを選択する可能性があります。

この回答をまだ読んでいる場合は、参照する具体的な例が必要だと思います。ここで書いたすべてのことを学ぶために使用したものを提供します:http ://wiki.icesoft.org/display/ICE/Spring+Web+Flow+2.3.1それは素晴らしい出発点です。簡単ですが徹底的です。

于 2012-08-17T12:27:15.090 に答える