0
votes

I have a web app in Spring MVC and would like to use this web app as a portlet in Liferay. I created portlet controller class, set web.xml, portlet.xml, liferay-portlet.xml and other files. When I add portlet to Liferay I get error in browser console:

Uncaught TypeError: Cannot read property 'liferay-form' of undefined

in barebone.jsp file

I use Liferay 6.2 with Tomcat and didn't notice any errors in server log files.

I have no idea how should I find where is the problem and don't know what is barebone.jsp file.

Project structure

enter image description here

SocialGraphUI-portlet.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-display.xml

    <?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-plugin-package.properties

    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

liferay-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>

portlet.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>

web.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>

pom.xml

<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>

liferay-portlet.tld

    <?xml version="1.0"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.1</jsp-version>
    <short-name>portlet</short-name>
    <uri>http://java.sun.com/portlet</uri>
    <tag>
        <name>actionURL</name>
        <tag-class>com.liferay.taglib.portlet.ActionURLTag</tag-class>
        <tei-class>com.liferay.taglib.portlet.ActionURLTei</tei-class>
        <body-content>JSP</body-content>
        <attribute>
            <name>copyCurrentRenderParameters</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>escapeXml</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>name</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>portletMode</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>secure</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>var</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>windowState</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
    <tag>
        <name>defineObjects</name>
        <tag-class>com.liferay.taglib.portlet.DefineObjectsTag</tag-class>
        <tei-class>com.liferay.taglib.portlet.DefineObjectsTei</tei-class>
        <body-content>empty</body-content>
    </tag>
    <tag>
        <name>namespace</name>
        <tag-class>com.liferay.taglib.portlet.NamespaceTag</tag-class>
        <body-content>JSP</body-content>
    </tag>
    <tag>
        <name>param</name>
        <tag-class>com.liferay.taglib.util.ParamTag</tag-class>
        <body-content>JSP</body-content>
        <attribute>
            <name>name</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>value</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
    <tag>
        <name>property</name>
        <tag-class>com.liferay.taglib.util.PropertyTag</tag-class>
        <body-content>JSP</body-content>
        <attribute>
            <name>name</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>value</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
    <tag>
        <name>renderURL</name>
        <tag-class>com.liferay.taglib.portlet.RenderURLTag</tag-class>
        <tei-class>com.liferay.taglib.portlet.RenderURLTei</tei-class>
        <body-content>JSP</body-content>
        <attribute>
            <name>copyCurrentRenderParameters</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>escapeXml</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>portletMode</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>secure</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>var</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>windowState</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
    <tag>
        <name>resourceURL</name>
        <tag-class>com.liferay.taglib.portlet.ResourceURLTag</tag-class>
        <tei-class>com.liferay.taglib.portlet.ResourceURLTei</tei-class>
        <body-content>JSP</body-content>
        <attribute>
            <name>cacheability</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>escapeXml</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>id</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>secure</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>var</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
</taglib>
2

2 Answers

1
votes

From the first glance, it looks like your web-app's javascript has conflicts with that of Liferay's. As you can see the browser complains 'Uncaught TypeError: Cannot read property 'liferay-form' of undefined'. This means as soon as you add your portlet on a page, it screws up Liferay's javascript. I would try removing references to all the js files from the jsp, and add them one by one to see which one has conflicts, and then resolve them.

JFYI, liferay-form could be referenced from one of these places: https://github.com/liferay/liferay-portal/search?utf8=%E2%9C%93&q=liferay-form, but you can't really figure out your culprit from these. My guess would be 'end.jsp', but I am not sure.

0
votes

First of all I would check all required dependencies for your portlet, for example these required to use liferay taglib:

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

From other hand make sure your portlet anatomy is equals as one providen in official sites:

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

For example you haven't mentioned about liferay-display.xml If this won't solve your problem, provide your portlet sources (configuration files, and jsp file throwing error are enough)