Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Morad Ahmad
Problem in simple JSP Portlet
September 8, 2010 10:40 AM
Answer

Morad Ahmad

Rank: Junior Member

Posts: 36

Join Date: June 16, 2010

Recent Posts

Hello,

I have following problem in a simple Java/jsp portlet:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>

<portlet:defineObjects/>

<p>
Hallo ${requestScope.test} .
</p>

<table>
<c:forEach var="l" items="<%=request.getAttribute("locations")%>">
<tr>
<b><c:out value="${l.name}" /></b>
<br />
${l.adresse}
<br />
<tt>${l.email}</tt>
<br />
${l.tel}
<br />
<br />
</tr>
</c:forEach>
</table>

but the reference such ${l.adresse} ect. are not resolved.


The Portlet class looks like:

public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {

List<Location> locations = new ArrayList<Location>();
locations.add(LocationsFactory.location1());
...
renderRequest.setAttribute("test", "Test");
renderRequest.setAttribute("locations", locations);
include(viewJSP, renderRequest, renderResponse);
}

protected void include(String path, RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {
PortletRequestDispatcher portletRequestDispatcher = getPortletContext()
.getRequestDispatcher(path);
if (portletRequestDispatcher == null) {
_log.error(path + " is not a valid include");
} else {
portletRequestDispatcher.include(renderRequest, renderResponse);
}
}
The result in browser is:

Hallo ${requestScope.test} .
${l.name}
${l.adresse}
${l.email}
${l.tel}

${l.name}
${l.adresse}
${l.email}
${l.tel}

${l.name}
${l.adresse}
${l.email}
${l.tel}

!!!
Corné Aussems
RE: Problem in simple JSP Portlet
September 8, 2010 11:56 AM
Answer

Corné Aussems

Rank: Liferay Legend

Posts: 1271

Join Date: October 3, 2006

Recent Posts

EL is not a part of JSP 1. in J2EE lower than 1.4 ;
In that case you could use Apache commons EL

JSP 2.0

So it all depends on your Java Container (Server);

What is your setup ?
Corné Aussems
RE: Problem in simple JSP Portlet
September 8, 2010 12:01 PM
Answer

Corné Aussems

Rank: Liferay Legend

Posts: 1271

Join Date: October 3, 2006

Recent Posts

Oh yeah don't forget !!
This should be your web.xml's dtd declaration

1
2
3<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
4xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5xsi:schemaLocation=
6"http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
7version="2.4">
Morad Ahmad
RE: Problem in simple JSP Portlet
September 8, 2010 12:06 PM
Answer

Morad Ahmad

Rank: Junior Member

Posts: 36

Join Date: June 16, 2010

Recent Posts

its tomcat 6 in the liferay donwload 6.0.4.

That's the pom.xml:

ependencies>
<dependency>
<groupId>com.commsen.liferay</groupId>
<artifactId>liferay-lib</artifactId>
<version>5.2.3-r2</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>

<!-- hibernate + spring -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.1.GA</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>

I think I must declare something in the jsp?? (<%=request.getAttribute("locations")%>) delivers the value but not ${locations} !!! I realy don't have any Idea...

Thanks for response.
Corné Aussems
RE: Problem in simple JSP Portlet
September 8, 2010 12:11 PM
Answer

Corné Aussems

Rank: Liferay Legend

Posts: 1271

Join Date: October 3, 2006

Recent Posts

I'm not really in to maven builds
<version>2.4</version>
But i'm sure you should check your web.xml
what version is that?
Morad Ahmad
RE: Problem in simple JSP Portlet
September 8, 2010 12:15 PM
Answer

Morad Ahmad

Rank: Junior Member

Posts: 36

Join Date: June 16, 2010

Recent Posts

Thanks!

That was the Problem. And which version is used as default? I put 2.5

<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_2_5.xsd"
version="2.5">


Morad.
Corné Aussems
RE: Problem in simple JSP Portlet
September 9, 2010 6:51 AM
Answer

Corné Aussems

Rank: Liferay Legend

Posts: 1271

Join Date: October 3, 2006

Recent Posts

i checked this further and for 2.5 you'll need this in web.xml

1
2
3    <jsp-config>
4        <jsp-property-group>
5            <url-pattern>*.jsp</url-pattern>
6            <el-ignored>false</el-ignored>
7        </jsp-property-group>
8    </jsp-config>


AFAIK this shouldn't be needed but it seems that somewhere this setting is set global to true

otherwise you could add this in your jsp headers
<%@ page isELIgnored ="false" %>