如果更改jsf页面位置,则primefaces treetable展开不起作用

时间:2015-05-29 17:08:31

标签: spring jsf spring-mvc jsf-2 primefaces

如果我的xhtml网页在WebContent文件夹中,则可以扩展Primefaces treetable,但如果我将同一网页移动到WEB-INF / views / jsf文件夹,则不会扩展。我对JSF很陌生,我不知道改变的地点和内容。

如果我的网页位于WEB-INF / views / jsf文件夹中,则仅显示根节点。如果我点击它,它就不会扩展。

HTML代码

<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <f:facet name="first">
        <meta http-equiv="X-UA-Compatible" content="IE=9" /> 
    </f:facet>
</h:head>
<h:body class="page">
    <h:outputStylesheet name="philos.css" />
    <h:outputStylesheet name="primefaces.css" />
    <h:form>
        <p:treeTable value="#{treeView.newRoot}" var="document" id="treeTable" >
            <p:column headerText="Name">
                <h:outputText value="#{document.name}" />
            </p:column>
            <p:column headerText="Size">
                <h:outputText value="#{document.size}" />
            </p:column>
            <p:column headerText="Type">
                <h:outputText value="#{document.type}" />
            </p:column>
        </p:treeTable>
    </h:form>
</h:body>
</html>

Managed Bean

package com.maintechnicalframework.sa.controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.servlet.http.HttpServletRequest;

import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.maintechnicalframework.common.constants.MainConstants;
import com.maintechnicalframework.common.controller.MainController;
import com.maintechnicalframework.common.model.LoginUserDetails;
import com.maintechnicalframework.sa.contants.SystemAttributeConstants;
import com.maintechnicalframework.sa.model.Document;
import com.maintechnicalframework.sa.service.SystemAttributeService;
import com.maintechnicalframework.sa.validator.SystemAttributeValidator;
@Controller
@RequestMapping("/faces")
@ManagedBean(name="treeView")
@ViewScoped
@SessionAttributes({ MainConstants.CURRENT_INSTANCE, MainConstants.LOGIN_USER_DETAILS, MainConstants.REQUEST_PARAM} )
public class SystemAttributeManagedBean extends MainController implements Serializable{
    @Autowired
    private SystemAttributeService systemAttributeService;
    @Autowired
    private SystemAttributeValidator systemAttributeValidator;
    private List<String> sampleList = new ArrayList<String>();

    @RequestMapping("/showTree")
    public String showTree( HttpServletRequest httpRequest, ModelMap model ){
        MainError.clearErrors();
        model.put(MainConstants.ERROR_OBJ, mainError);
        validateSSO(model, systemAttributeValidator, true ); 
      if( loginUserDetails == null ){
          model.addAttribute( MainConstants.INVALID_INFO, MainConstants.INVALID_SSO_INFO );
          return MainConstants.INVALID_SSO_PAGE;
      }else{
          return SystemAttributeConstants.EDIT_TREE;
      }

    }
    private TreeNode root;
    TreeNode newRoot;
    private Document selectedDocument;

    @PostConstruct
    public void init() {
        createDocuments();
    }
    public TreeNode createDocuments() {
        newRoot = new DefaultTreeNode(new Document("Files", "-", "Folder"), null);

        TreeNode documents = new DefaultTreeNode(new Document("Documents", "-", "Folder"), newRoot);
        TreeNode pictures = new DefaultTreeNode(new Document("Pictures", "-", "Folder"), newRoot);
        TreeNode movies = new DefaultTreeNode(new Document("Movies", "-", "Folder"), newRoot);

        TreeNode work = new DefaultTreeNode(new Document("Work", "-", "Folder"), documents);
        TreeNode primefaces = new DefaultTreeNode(new Document("PrimeFaces", "-", "Folder"), documents);

        //Documents
        TreeNode expenses = new DefaultTreeNode("document", new Document("Expenses.doc", "30 KB", "Word Document"), work);
        TreeNode resume = new DefaultTreeNode("document", new Document("Resume.doc", "10 KB", "Word Document"), work);
        TreeNode refdoc = new DefaultTreeNode("document", new Document("RefDoc.pages", "40 KB", "Pages Document"), primefaces);

        //Pictures
        TreeNode barca = new DefaultTreeNode("picture", new Document("barcelona.jpg", "30 KB", "JPEG Image"), pictures);
        TreeNode primelogo = new DefaultTreeNode("picture", new Document("logo.jpg", "45 KB", "JPEG Image"), pictures);
        TreeNode optimus = new DefaultTreeNode("picture", new Document("optimusprime.png", "96 KB", "PNG Image"), pictures);

        //Movies
        TreeNode pacino = new DefaultTreeNode(new Document("Al Pacino", "-", "Folder"), movies);
        TreeNode deniro = new DefaultTreeNode(new Document("Robert De Niro", "-", "Folder"), movies);

        TreeNode scarface = new DefaultTreeNode("mp3", new Document("Scarface", "15 GB", "Movie File"), pacino);
        TreeNode carlitosWay = new DefaultTreeNode("mp3", new Document("Carlitos' Way", "24 GB", "Movie File"), pacino);

        TreeNode goodfellas = new DefaultTreeNode("mp3", new Document("Goodfellas", "23 GB", "Movie File"), deniro);
        TreeNode untouchables = new DefaultTreeNode("mp3", new Document("Untouchables", "17 GB", "Movie File"), deniro);

        return newRoot;
    }
    public TreeNode getNewRoot() {
        return newRoot;
    }
    public TreeNode getRoot() {
        return root;
    }
    public List<String> getListOfString(){
        LoginUserDetails loginUserDetails = (LoginUserDetails)getSessionObj(MainConstants.LOGIN_USER_DETAILS);
        sampleList.add("One");sampleList.add("Two");sampleList.add("Three");sampleList.add("Four");
        return sampleList;
    }
   /* public void actionHandler(ActionEvent event)throws Exception{
        System.out.println("Jjjj");
    }*/
    public Document getSelectedDocument() {
        return selectedDocument;
    }

    public void setSelectedDocument(Document selectedDocument) {
        this.selectedDocument = selectedDocument;
    }
}

我的-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"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    ">

    <!-- Enable annotation driven controllers, validation etc... -->
    <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"/>
    <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
        <!-- Turn off working out content type based on URL file extension, should fall back to looking at the Accept headers -->
        <property name="favorPathExtension" value="false" />
    </bean>
    <context:annotation-config />
    <context:component-scan base-package = "com.mycompany.ondemand,com.oracle.ondemand.crm,com.maintechnicalframework"/>
    <context:property-placeholder location="/WEB-INF/properties/config.properties"/>

    <bean id="applicationContextProvider" class="com.oracle.ondemand.crm.framework.context.ApplicationContextProvider"/>

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
    </bean>

    <mvc:interceptors>
        <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" depends-on="localeMap">
            <property name="paramName" value="language" />
            <property name="localeMap" ref="localeMap" />
        </bean>
    </mvc:interceptors>
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />

    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <!-- <property name="basename" value="file:/C:/XXXXX/messages" /> -->
        <property name="basename" value="classpath:messages" />
        <property name="fallbackToSystemLocale" value="false"/>
        <property name="defaultEncoding" value="UTF-8"/>
    </bean>

</beans>

的Web.xml

<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_3_0.xsd"
      version="3.0">
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/*-Config.xml</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
</context-param>
<filter>
    <filter-name>SetCharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>SetCharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <!-- CERT Implementation START -->
  <filter>
    <filter-name>csrfFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <async-supported>true</async-supported>
</filter>
<filter-mapping>
    <filter-name>csrfFilter</filter-name>
    <url-pattern>/mycompany/*</url-pattern> 
</filter-mapping>
<!-- CERT Implementation END -->
  <session-config>
    <session-timeout>60</session-timeout>
  </session-config>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
  </listener>
    <display-name>systemAttribute</display-name>
    <servlet>
        <servlet-name>systemAttribute</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>systemAttribute</servlet-name>
        <url-pattern>/mycompany/*</url-pattern>
    </servlet-mapping>
    <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>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
    <!-- CERT Implementation START -->
  <error-page>
    <error-code>403</error-code>
    <location>/unauthorizedPage.jsp</location>
</error-page>
<!-- CERT Implementation END -->
</web-app>

1 个答案:

答案 0 :(得分:1)

我也遇到过这个问题。我确实解决了以下步骤: 第1步:将您的XHTML文件移动到webcontent文件夹中。 第2步:由于webcontent中的所有文件都允许公共访问,因此出于安全原因,您需要在web.xml中添加以下条目。

请点击链接了解安全限制: Prevent direct access to composite components by placing them inside /WEB-INF