2013-06-02 52 views
1

我的名字是Tomasz,这是我的第一个问题。这是我的问题。Spring-Webflow + Primefaces应用程序无法正常工作

我是一名初级Java EE开发人员,我在Java EE,Spring,Spring-Webflow,JSF 2和Primefaces方面拥有4个飞蛾经验。我想通过自己的Web应用程序来了解更多信息。 我没有使用我提到的技术开始一个新项目的经验,所以基本上我复制了一个模板应用程序并稍微改变了它(主要是删除了现在不需要的不必要的功能)。所以我的应用程序包含:
- 春3.2.2
- 春天的Webflow 2.3.2
- JSF 2.1.22
- Primefaces 3.5
- 和Hibernate JPA(没关系,这部分做工不错) 。

作为服务器,我使用Tomcat 7.0.40。

我使用很多配置教程配置了我的应用程序。应用程序起作用,它没有警告,但它不能正常工作。让我告诉你的屏幕截图:

Firt一个,当我启动应用程序,它看起来像这样:
http://oi44.tinypic.com/2wd4od3.jpg

但我按F5刷新浏览器之后,它看起来像它应该从一开始就:
http://oi39.tinypic.com/17fr06.jpg

对我来说这是一个非常奇怪的行为,我不知道它为什么会发生。浏览器无关紧要。我已经在Chrome,FireFox和IE上试过了 - 效果相同。

另外p:commandLink似乎不理我。我点击它并没有任何反应。当我有选择

ajax="false" 

使它看起来像页面被刷新,但仍然没有任何反应。我在工作中用primefaces和swf工作了很多,而这一切从未发生过。

下面是我的应用程序的一些细节,我可以要求张贴的所有内容:

模板(main.xhtml):

<!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:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:p="http://primefaces.org/ui"> 
<ui:include src="/WEB-INF/layout/fragments/layout.xhtml" /> 
</html> 

布局(layout.xhtml):

<!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:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:p="http://primefaces.org/ui"> 
<f:view contentType="text/html" encoding="UTF-8"> 
    <h:head> 
    </h:head> 

    <h:body> 
     <!-- outputStyle have to be here, otherwise css order is wrong --> 
     <h:outputStylesheet id="cssStandard" library="css" name="standard.css" /> 
     <!--  <h:outputStylesheet id="cssStandard" library="css" name="simple.css" /> --> 
     <h:form> 
      <div id="glass" 
       style="position: absolute; width: 100%; height: 100%; z-index: 2000; display: none;"></div> 

      <ui:include src="/WEB-INF/layout/fragments/ajaxError.xhtml" /> 

      <p:layout id="layout" fullPage="false" 
       style="width: 1000px; height: 900px; margin: 0 auto;"> 
       <p:layoutUnit position="north" size="150"> 
        <ui:include src="/WEB-INF/layout/fragments/north.xhtml" /> 
       </p:layoutUnit> 
       <p:layoutUnit position="center"> 
        <h:form> 
         <ui:insert name="content" /> 
        </h:form> 
       </p:layoutUnit> 
      </p:layout> 

      <p:outputPanel id="dialogs" style="display:block; overflow: auto;"> 
       <ui:insert name="dialogs" /> 
      </p:outputPanel> 
     </h:form> 
    </h:body> 

</f:view> 
</html> 

导航菜单(north.x HTML):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:p="http://primefaces.org/ui"> 
    <h:form> 
     <a href="#{facesContext.externalContext.requestContextPath}"> <p:graphicImage 
       name="logo.png" library="images/application" /> 
     </a> 
     <h:panelGrid columns="3" style="width: 100%"> 
      <h:column> 
       <p:menubar style="width: 300px"> 
        <p:menuitem value="Strona Główna" action="forwardTo" ajax="false"> 
         <f:setPropertyActionListener target="#{flowController.flowId}" 
          value="main" /> 
        </p:menuitem> 
        <p:submenu label="MENU_2"> 
        </p:submenu> 
       </p:menubar> 
      </h:column> 
      <h:column> 
       <h:outputText value="Zalogowany jako: " style="float: right" /> 
      </h:column> 
      <p:column> 
       <p:menuButton 
        value="#{mainController.loggedUser != null ? mainController.loggedUser.login : 'Gość'}"> 
        <p:menuitem value="Zaloguj" action="forwardTo" ajax="false"> 
         <f:setPropertyActionListener target="#{flowController.flowId}" 
          value="login" /> 
        </p:menuitem> 
        <p:menuitem value="Wyloguj" /> 
       </p:menuButton> 
      </p:column> 
     </h:panelGrid> 


    </h:form> 
</ui:composition> 

基flow.xml

<?xml version="1.0" encoding="UTF-8"?> 
<flow xmlns="http://www.springframework.org/schema/webflow" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/webflow 
     http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd" 
    abstract="true"> 

    <end-state id="endAndForwardTo" view="flowRedirect:#{flowController.flowId}" /> 

    <global-transitions> 
     <transition on="forwardTo" to="endAndForwardTo" validate="false" /> 
     <transition on="endAndForwardTo" to="endAndForwardTo" /> 
    </global-transitions> 


</flow> 

FlowController.java

package tomashoov.polskielowiska.flow; 

import org.apache.log4j.Logger; 
import org.springframework.context.annotation.Scope; 
import org.springframework.stereotype.Component; 

@Component 
@Scope("session") 
public class FlowController { 

    private Logger LOG = Logger.getLogger(FlowController.class); 

    public final static String MAIN = "main"; 
    public final static String LOGIN = "login"; 

    private String flowId = MAIN; 

    public String getFlowId() { 
     return flowId; 
    } 

    public void setFlowId(String flowId) { 
     this.flowId = flowId; 
    } 
} 

如果需要更多的详细信息,请告诉我。

回答

1

我遇到了完全相同的问题,我在这个问题上挖了一点,并且我做了一个解决这个问题的工作(因为我在我的项目中很晚)。稍后我会回来一个强大的解决方案,但这里是我得到的:

您正在使用Spring Webflow开始页面是index.jsp,​​强制重定向到主Web流。

你会发现在你的浏览器控制台2 JavaScript错误:

  1. ReferenceError: $ is not defined
  2. ReferenceError: PrimeFaces is not defined

这些错误是由于缺少JavaScript文件:

  1. 的JQuery的JavaScript。
  2. Primefaces JavaScript。
  3. 布局JavaScript。

请注意,还有CSS文件丢失,这就是为什么页面布局大小和位置错过了。

因此,显然<h:head></h:head>标签没有在重定向中获取一些Primefaces JavaScript文件和CSS。我发现一个问题here与重定向资源获取失败。建议的解决方案是在<h:head></h:head>中添加<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />。所以,我在<h:head></h:head>中添加了缺少的脚本和CSS文件,它的功能就像一个魅力。

<h:outputStylesheet library="primefaces" name="primefaces.css" /> 
<h:outputStylesheet library="primefaces" name="layout/layout.css" /> 

<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" /> 
<h:outputScript library="primefaces" name="jquery/jquery-plugins.js" target="head" /> 
<h:outputScript library="primefaces" name="primefaces.js" target="head" /> 
<h:outputScript library="primefaces" name="layout/layout.js" target="head" />