将JSF表单提交给其他主机

时间:2015-07-23 08:00:14

标签: jsf-2 portal viewexpiredexception

我想为Admin创建登录功能,以便管理员可以作为任何用户(在用户门户中)登录(从Admin-portal)。 (这是在两个不同的主机中运行的两个不同的门户网站。)

在Admin-portal中,我已经写过了

<p:dialog>  
    <form action="http://user-portal.com/index.jsf" method="post"
        target="_blank">
        <h:inputHidden id="adminId" value="#{userListBean.openAdminId}"></h:inputHidden>
        <h:inputHidden id="clientId" value="#{userListBean.openClientId}"></h:inputHidden>
        <!-- some other security parameters -->
       <input type="submit" value="login"></input>
    </form>
</p:dialog>

问题出在用户门户网站上。
index.jsf

<h:body>
    #{customLogin}
</h:body>  

CustomLogin bean

@Named("customLogin")
@SessionScoped
public class CustomLogin implements Serializable {
.
.
@PostConstruct
public void customLoginPage() {
    HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance()
                    .getExternalContext().getRequest();
    Map<String, String[]> requestParaMap = request.getParameterMap();
    // some admin and user validation and setting other injected bean property base on it
    HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance()
                    .getExternalContext().getResponse();
    string serverName = request.getServerName();
    response.sendRedirect(serverName+ "/home.jsf");
    // also tried this
    // facesContext.getExternalContext().redirect("/home.jsf");
    return;
}

CustomLogin bean是会话范围的,并且在postconstruct中调用方法“customLoginPage”。所以它在JSF生命周期的“RESTORE_VIEW”阶段运行。

我收到以下错误:

javax.faces.application.ViewExpiredException: viewId:/index.jsf - View /index.jsf could not be restored.
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:205) [jsf-impl-2.1.28.redhat-3.jar:2.1.28.redhat-3]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.28.redhat-3.jar:2.1.28.redhat-3]
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [jsf-impl-2.1.28.redhat-3.jar:2.1.28.redhat-3]
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.28.redhat-3.jar:2.1.28.redhat-3]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.1.28.Final-redhat-1.jar:2.1.28.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
    .
    .
    .
12:21:24,683 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/].[Faces Servlet]] (http-localhost/127.0.0.1:8080-1) JBWEB000236: Servlet.service() for servlet Faces Servlet threw exception: java.lang.IllegalStateException
    at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:420) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
    at com.sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl.java:602) [jsf-impl-2.1.28.redhat-3.jar:2.1.28.redhat-3]
    at javax.faces.context.ExternalContextWrapper.redirect(ExternalContextWrapper.java:462) [jboss-jsf-api_2.1_spec-2.1.28.Final-redhat-1.jar:2.1.28.Final-redhat-1]

很少 web.xml 可能有用的内容

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
</context-param>
<context-param>
  <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
  <param-value>false</param-value>
</context-param>

<context-param>             
  <param-name>javax.faces.RESOURCE_EXCLUDES</param-name>
  <param-value>.xhtml .class .properties .xml</param-value>
</context-param>

<context-param>
    <param-name>facelets.DEVELOPMENT</param-name>
    <param-value>true</param-value>
</context-param>

<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>*.jsf</url-pattern>
</servlet-mapping>

我看过ViewExpiredException by BalusC。但是这里对用户门户的每个请求都是新鲜的。另外,当我将javax.faces.STATE_SAVING_METHOD更改为客户端时,我收到“GZIP异常”。

0 个答案:

没有答案