未捕获的TypeError:无法读取属性' liferay-form'未定义的

时间:2014-12-12 10:06:20

标签: liferay liferay-6 spring-portlet-mvc

我在Spring MVC中有一个Web应用程序,并希望将此Web应用程序用作Liferay中的portlet。我创建了portlet控制器类,设置了web.xml, portlet.xml, liferay-portlet.xml和其他文件。当我向Liferay添加portlet时,我在浏览器控制台中收到错误:

Uncaught TypeError: Cannot read property 'liferay-form' of undefined
<{1>}文件中的

我将Liferay 6.2与Tomcat一起使用,并没有注意到服务器日志文件中的任何错误。

我不知道如何找到问题的位置,并且不知道barebone.jsp文件是什么。

项目结构

enter image description here

SocialGraphUI-portlet.xml中

barebone.jsp

的liferay-display.xml

    <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd">

   <context:component-scan base-package="socialgraphui.controller" />

   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/jsp/" />
      <property name="suffix" value=".jsp" />
      <property name="viewClass"
                  value="org.springframework.web.servlet.view.JstlView" />
   </bean>

   <mvc:annotation-driven>
    <mvc:message-converters>
        <bean class="org.springframework.http.converter.json.GsonHttpMessageConverter" />
    </mvc:message-converters>
    </mvc:annotation-driven>

    <bean class="org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> 
    <bean class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> 

   <!-- Spring MVC Message Source -->
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="useCodeAsDefaultMessage" value="true"/>
        <property name="basenames">
            <list>
                <value>content.socialGraph</value>
            </list>
        </property>
    </bean>

</beans>

liferay-plugin-package.properties

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.2.0//EN" "http://www.liferay.com/dtd/liferay-display_6_2_0.dtd">
<display>
    <category name="Social">
        <category name="Other">
            <portlet id="SocialGraphUI" />
        </category>
    </category>
</display>

的liferay-portlet.xml中

    name=serverTypeConfig
module-group-id=liferay
module-incremental-version=1
tags=
short-description=
change-log=
page-url=http://www.liferay.com
author=Liferay, Inc.
licenses=LGPL
portal-dependency-jars=jstl-api.jar,jstl-impl.jar

portlet.xml中

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd">
<liferay-portlet-app>
    <portlet>
        <portlet-name>SocialGraphUI</portlet-name>
        <instanceable>false</instanceable>
        <requires-namespaced-parameters>false</requires-namespaced-parameters>
        <header-portlet-css>/styles/layout-default.css</header-portlet-css>
        <header-portlet-css>/styles/bootstrap_2.3.2.min.css</header-portlet-css>
        <header-portlet-css>/styles/bootstrap.icon-large.css</header-portlet-css>
        <header-portlet-css>/styles/datepicker.css</header-portlet-css>
        <header-portlet-css>/styles/chosen.css</header-portlet-css>
        <header-portlet-css>/styles/jquery.dataTables_1.10.3.css</header-portlet-css>
        <header-portlet-css>/styles/bootstrapValidator_0.5.2.css</header-portlet-css>
        <header-portlet-css>/styles/font-awesome.css</header-portlet-css>
        <header-portlet-css>/styles/bootstrap-slider.css</header-portlet-css>
        <header-portlet-css>/styles/main.css</header-portlet-css>
        <header-portlet-javascript>/scripts/aui-min_2.0.0.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/jquery-1.9.1.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/bootstrap.min_2.3.2.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/bootstrapValidator_0.5.2.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/bootstrapValidator_cs_CZ.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/bootstrapValidator_en_US.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/jquery-ui-1.9.2.custom.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/jquery.layout.min-1.3.0.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/bootstrap-datepicker.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/bootstrap-slider.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/bootstrap-filestyle_1.1.2.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/chosen.jquery.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/chosen.proto.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/d3.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/graph.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/jquery.dataTables_1.10.3.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/underscore_1.7.0.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/set.layout.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/initialize.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/main.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/listeners_filter.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/listeners_details.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/listeners_modals.js</header-portlet-javascript>
        <header-portlet-javascript>/scripts/validation.js</header-portlet-javascript>
    </portlet>

    <role-mapper>
        <role-name>administrator</role-name>
        <role-link>Administrator</role-link>
    </role-mapper>
    <role-mapper>
        <role-name>guest</role-name>
        <role-link>Guest</role-link>
    </role-mapper>
    <role-mapper>
        <role-name>power-user</role-name>
        <role-link>Power User</role-link>
    </role-mapper>
    <role-mapper>
        <role-name>user</role-name>
        <role-link>User</role-link>
    </role-mapper>

</liferay-portlet-app>

的web.xml

    <?xml version='1.0' encoding='UTF-8' ?>
<portlet-app
    xmlns='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xsi:schemaLocation='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd'
    version='2.0'>

    <portlet>
        <portlet-name>SocialGraphUI</portlet-name>
        <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
        <init-param>
            <name>contextConfigLocation</name>
            <value>/WEB-INF/SocialGraphUI-portlet.xml</value>
        </init-param>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
        </supports>
        <supported-locale>en</supported-locale>
        <supported-locale>cs</supported-locale>
        <resource-bundle>content.socialGraph</resource-bundle>
    </portlet>


</portlet-app>

的pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <!-- - Loads the root application context of this web app at startup, - by default from "/WEB-INF/applicationContext.xml". - Note that you need to fall back to Spring's ContextLoaderServlet for - J2EE servers that do not follow the Servlet 2.4 initialization order. - - Use WebApplicationContextUtils.getWebApplicationContext(servletContext) 
        - to access it anywhere in the web application, outside of the framework. - - The root context is the parent of all servlet-specific contexts. - This means that its beans are automatically available in these child contexts, - both for getBean(name) calls and (external) bean references. -->

    <jsp-config>
        <taglib>
            <taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
            <taglib-location>/WEB-INF/tld/liferay-portlet.tld</taglib-location>
        </taglib>
    </jsp-config>

    <servlet>
        <servlet-name>view-servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>view-servlet</servlet-name>
        <url-pattern>/WEB-INF/servlet/view</url-pattern>
    </servlet-mapping>

</web-app>

的liferay-portlet.tld

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>test</groupId>
<artifactId>socialgraphui</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>socialgraphui</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring.version>4.1.0.RELEASE</spring.version>
    <liferay.version>6.2.1</liferay.version>
    <spring.data.version>1.6.1.RELEASE</spring.data.version>
</properties>

<dependencies>
    <!-- LifeRay Dependency -->
    <dependency>
        <groupId>com.liferay.portal</groupId>
        <artifactId>portal-service</artifactId>
        <version>${liferay.version}</version>
        <type>jar</type>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>  
        <groupId>com.google.code.gson</groupId>  
        <artifactId>gson</artifactId>  
        <version>2.2.4</version>  
    </dependency>  
    <dependency>
        <groupId>uk.com.robust-it</groupId>
        <artifactId>cloning</artifactId>
        <version>1.7.4</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc-portlet</artifactId>
        <version>${spring.version}</version>
        <type>jar</type>
    </dependency>

    <!-- Spring Data JPA deps-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <!-- END Spring Data JPA deps-->

    <dependency>
        <groupId>javax.portlet</groupId>
        <artifactId>portlet-api</artifactId>
        <version>2.0</version>
        <type>jar</type>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.codehaus.jettison</groupId>
        <artifactId>jettison</artifactId>
        <version>1.3.5</version>
    </dependency>

    <!-- GOOGLE visualization -->
    <dependency>
        <groupId>com.google.visualization</groupId>
        <artifactId>visualization-datasource</artifactId>
        <version>1.1.1</version>
    </dependency>       

    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-core</artifactId>
        <version>1.0.3.RELEASE</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>commons-httpclient</groupId>
        <artifactId>commons-httpclient</artifactId>
        <version>3.1</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>${spring.data.version}</version>
        <type>jar</type>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

2 个答案:

答案 0 :(得分:1)

从第一眼看,您的网络应用程序的javascript与Liferay的浏览器有冲突。正如您所看到的,浏览器会抱怨&#39; Uncaught TypeError:无法读取未定义&#39;的属性&#39; liferay-form&#39; 。这意味着只要在页面上添加portlet,它就会搞砸Liferay的javascript。我会尝试从jsp中删除对所有js文件的引用,并逐个添加它们以查看哪个有冲突,然后解决它们。

JFYI,liferay-form可以从其中一个地方引用:https://github.com/liferay/liferay-portal/search?utf8=%E2%9C%93&q=liferay-form,但你无法从这些地方找出罪魁祸首。我的猜测是&#39; end.jsp&#39;,但我不确定。

答案 1 :(得分:0)

首先,我会检查所有必需的portlet依赖项,例如使用liferay taglib所需的依赖项:

 <dependency>
       <groupId>com.liferay.portal</groupId>
       <artifactId>util-taglib</artifactId>
       <version>${liferay.version}</version>
       <scope>provided</scope>
 </dependency>

另一方面,确保您的portlet解剖结构与官方网站中的一个提供者相同:

https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/liferay-plugin-types-to-develop-with-maven https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/anatomy-of-a-portl-4

例如,您还没有提到过liferay-display.xml如果这不能解决您的问题,请提供您的portlet源(配置文件和jsp文件抛出错误就足够了)