Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Bryancan Cantwell
Struts actions in links
April 3, 2008 3:44 PM
Answer

Bryancan Cantwell

Rank: Junior Member

Posts: 26

Join Date: June 18, 2006

Recent Posts

I have built a struts portlet that has a view and an edit mode and works fine.
Now I want to add a details action that I can click a link in view and the details action will display.
This is NOT an ext portlet it is standalone WAR deployable!!!!!!!!!!!!

Here is struts_config:
 1
 2<?xml version="1.0" encoding="UTF-8"?>
 3<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
 4
 5<struts-config>
 6    <action-mappings>
 7        <action path="/tester/view" type="com.portlet.tester.action.ViewAction">
 8            <forward name="portlet.tester.view" path="portlet.tester.view"></forward>
 9        </action>
10        <action path="/tester/edit" type="com.portlet.tester.action.EditAction">
11            <forward name="portlet.tester.edit" path="portlet.tester.edit"></forward>
12        </action>
13        <action path="/tester/detail" type="com.portlet.tester.action.DetailAction">
14            <forward name="portlet.tester.detail" path="portlet.tester.detail"></forward>
15        </action>
16    </action-mappings>
17    <plug-in className="org.apache.struts.tiles.TilesPlugin">
18        <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"></set-property>
19        <set-property property="moduleAware" value="true"></set-property>
20        <set-property property="definitions-parser-validate" value="true"></set-property>
21    </plug-in>
22</struts-config>


Here is tiles-def.xml:
 1
 2<?xml version="1.0" encoding="UTF-8"?>
 3<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
 4
 5<tiles-definitions>
 6    <definition name="portlet.TESTER" path="/html/portlet/tester/template.jsp"></definition>
 7    <definition extends="portlet.TESTER" name="portlet.tester.view">
 8        <put name="portlet_content" value="/portlet/tester/view.jsp"></put>
 9    </definition>
10    <definition extends="portlet.TESTER" name="portlet.tester.edit">
11        <put name="portlet_content" value="/portlet/tester/edit.jsp"></put>
12    </definition>
13    <definition  extends="portlet.TESTER" name="portlet.tester.detail">
14        <put name="portlet_content" value="/portlet/tester/detail.jsp" />
15    </definition>
16
17</tiles-definitions>


Here is portlet.xml:
 1
 2<?xml version="1.0" encoding="UTF-8"?>
 3
 4<portlet-app>
 5    <portlet>
 6        <portlet-name>TESTER</portlet-name>
 7        <display-name>tester</display-name>
 8        <portlet-class>org.apache.portals.bridges.struts.StrutsPortlet</portlet-class>
 9        <init-param>
10            <name>ViewPage</name>
11            <value>/portlet_action/tester/view</value>
12        </init-param>
13        <init-param>
14            <name>EditPage</name>
15            <value>/portlet_action/tester/edit</value>
16            </init-param>
17        <init-param>
18            <name>ServletContextProvider</name>
19            <value>com.liferay.util.bridges.struts.LiferayServletContextProviderWrapper</value>
20        </init-param>
21        <expiration-cache>0</expiration-cache>
22        <supports>
23            <mime-type>text/html</mime-type>            
24            <portlet-mode>edit</portlet-mode>
25        </supports>
26        <security-role-ref>
27            <role-name>power-user</role-name>
28        </security-role-ref>
29        <security-role-ref>
30            <role-name>user</role-name>
31        </security-role-ref>
32        <portlet-info>
33            <title>tester</title>
34            <short-title>tester</short-title>
35            <keywords>tester</keywords>
36        </portlet-info>
37    </portlet>
38</portlet-app>


liferay-portlet.xml:
 1
 2<?xml version="1.0" encoding="UTF-8"?>
 3
 4<liferay-portlet-app>
 5    <portlet>
 6        <portlet-name>TESTER</portlet-name>
 7        <struts-path>/tester/view</struts-path>
 8        <use-default-template>true</use-default-template>
 9        <portlet-url-class>com.liferay.portal.apache.bridges.struts.LiferayStrutsPortletURLImpl</portlet-url-class>
10    </portlet>
11    <role-mapper>
12        <role-name>administrator</role-name>
13        <role-link>Administrator</role-link>
14    </role-mapper>
15    <role-mapper>
16        <role-name>guest</role-name>
17        <role-link>Guest</role-link>
18    </role-mapper>
19    <role-mapper>
20        <role-name>power-user</role-name>
21        <role-link>Power User</role-link>
22    </role-mapper>
23    <role-mapper>
24        <role-name>user</role-name>
25        <role-link>User</role-link>
26    </role-mapper>
27</liferay-portlet-app>


web.xml:
 1
 2<?xml version="1.0" encoding="UTF-8"?>
 3
 4<web-app>
 5    <display-name>tester</display-name>
 6    <context-param>
 7        <param-name>company_id</param-name>
 8        <param-value>liferay.com</param-value>
 9    </context-param>
10    <listener>
11        <listener-class>com.liferay.portal.kernel.servlet.PortletContextListener</listener-class>
12    </listener>
13    <servlet>
14        <servlet-name>TESTER</servlet-name>
15        <servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
16        <init-param>
17            <param-name>portlet-class</param-name>
18            <param-value>org.apache.portals.bridges.struts.StrutsPortlet</param-value>
19        </init-param>
20        <load-on-startup>0</load-on-startup>
21    </servlet>
22    <servlet>
23        <servlet-name>PortletActionServlet</servlet-name>
24        <servlet-class>com.liferay.util.bridges.struts.LiferayPortletServlet</servlet-class>
25        <init-param>
26            <param-name>config</param-name>
27            <param-value>/WEB-INF/struts-config.xml</param-value>
28        </init-param>
29        <load-on-startup>1</load-on-startup>
30    </servlet>
31    <servlet-mapping>
32        <servlet-name>TESTER</servlet-name>
33        <url-pattern>/TESTER/*</url-pattern>
34    </servlet-mapping>
35    <servlet-mapping>
36        <servlet-name>PortletActionServlet</servlet-name>
37        <url-pattern>/portlet_action/*</url-pattern>
38    </servlet-mapping>
39    <taglib>
40        <taglib-uri>http://java.sun.com/portlet</taglib-uri>
41        <taglib-location>/WEB-INF/tld/liferay-portlet.tld</taglib-location>
42    </taglib>
43    <taglib>
44        <taglib-uri>http://struts.apache.org/tags-bean</taglib-uri>
45        <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
46    </taglib>
47    <taglib>
48        <taglib-uri>http://portals.apache.org/bridges/struts/tags-portlet-html</taglib-uri>
49        <taglib-location>/WEB-INF/tld/struts-portlet-html.tld</taglib-location>
50    </taglib>
51    <taglib>
52        <taglib-uri>http://struts.apache.org/tags-logic</taglib-uri>
53        <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
54    </taglib>
55    <taglib>
56        <taglib-uri>http://struts.apache.org/tags-nested</taglib-uri>
57        <taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
58    </taglib>
59    <taglib>
60        <taglib-uri>http://struts.apache.org/tags-tiles</taglib-uri>
61        <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
62    </taglib>
63</web-app>


init.jsp:
 1
 2<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
 3<%@ taglib uri="http://portals.apache.org/bridges/struts/tags-portlet-html" prefix="html" %>
 4<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
 5<%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %>
 6<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
 7
 8<%@ page import="java.util.Enumeration" %>
 9<%@ page import="java.util.HashMap" %>
10<%@ page import="java.util.Iterator" %>
11<%@ page import="java.util.Map" %>


template.jsp:
1
2<%@ include file="/html/portlet/tester/init.jsp" %>
3
4<tiles:useAttribute id="tilesPortletContent" name="portlet_content" classname="java.lang.String" ignore="true" />
5
6<div>
7    <jsp:include page="<%= \"/html\" + tilesPortletContent %>" flush="true" />
8</div>


view.jsp:
1
2<%@ include file="/html/portlet/tester/init.jsp" %>
3
4Hello world!
5
6<li>
7<html:link page="/detail">Link to details</html:link>
8</li>


detail.jsp
1
2<%@ include file="/html/portlet/tester/init.jsp" %>
3
4DETAIL PAGE!


edit.page:
1
2<%@ include file="/html/portlet/tester/init.jsp" %>
3
4EDIT PAGE!



I cannot for the life of me make the link actually work and show the detail.jsp content in the poirtlet!
The view and the edit work fine...

What is wrong?
Attachments: tester.zip (3,189.3k)
Jerry Niu
RE: Struts actions in links
April 3, 2008 4:42 PM
Answer

Jerry Niu

LIFERAY STAFF

Rank: Expert

Posts: 451

Join Date: June 21, 2006

Recent Posts

This is code from 4.0.X. I haven't tested it in a long time.

1
2<html:link page="/portlet_action/basic_struts_portlet/subscribe/render">a link</html:link>
Bryancan Cantwell
RE: Struts actions in links
April 4, 2008 8:33 AM
Answer

Bryancan Cantwell

Rank: Junior Member

Posts: 26

Join Date: June 18, 2006

Recent Posts

Thx for the reply, but when I adapt this to my sample app from above, the portlet goes blank.
if I put in the wrong action to test, it does error, so I must have the link right to a point.

1
2<html:link page="/portlet_action/tester/detail">a link</html:link>
Victor Zorin
RE: Struts actions in links
April 15, 2008 2:07 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

Try the following code.
1
2<bean:define id="detailURL" value=""/>
3<portlet:renderURL var="detailURL" windowState="MAXIMIZED">
4    <portlet:param name="_spage" value="/portlet_action/tester/detail" />
5</portlet:renderURL>
6<a href="<%=detailURL">View Details</a>


or

1
2<a href="<portlet:renderURL var="detailURL" windowState="MAXIMIZED">
3    <portlet:param name="_spage" value="/portlet_action/tester/detail" />
4</portlet:renderURL>">View Details</a>
Bryancan Cantwell
RE: Struts actions in links
May 9, 2008 10:18 AM
Answer

Bryancan Cantwell

Rank: Junior Member

Posts: 26

Join Date: June 18, 2006

Recent Posts

I've had success here in getting to my struts actions.
I have one last challenge:
When i create a url like this:
<portlet:renderURL windowState="exclusive"><portlet:param name="_spage" value="/portlet_action/mass_acknowledge/detail" /></portlet:renderURL>

the resulting page comes back wrapped with
1<div>
tags

I should see:
 1{
 2page: 1,
 3total: 239,
 4rows: [
 5{id:'AD',cell:['AD','ANDORRA','Andorra','AND','20']},
 6{id:'AE',cell:['AE','UNITED ARAB EMIRATES','United Arab Emirates','ARE','784']},
 7{id:'AF',cell:['AF','AFGHANISTAN','Afghanistan','AFG','4']},
 8{id:'AG',cell:['AG','ANTIGUA AND BARBUDA','Antigua and Barbuda','ATG','28']},
 9{id:'AI',cell:['AI','ANGUILLA','Anguilla','AIA','660']},
10{id:'AL',cell:['AL','ALBANIA','Albania','ALB','8']},
11{id:'AM',cell:['AM','ARMENIA','Armenia','ARM','51']},
12{id:'AN',cell:['AN','NETHERLANDS ANTILLES','Netherlands Antilles','ANT','530']},
13{id:'AO',cell:['AO','ANGOLA','Angola','AGO','24']},
14{id:'AQ',cell:['AQ','ANTARCTICA','Antarctica','','']},
15{id:'AR',cell:['AR','ARGENTINA','Argentina','ARG','32']},
16{id:'AS',cell:['AS','AMERICAN SAMOA','American Samoa','ASM','16']},
17{id:'AT',cell:['AT','AUSTRIA','Austria','AUT','40']},
18{id:'AU',cell:['AU','AUSTRALIA','Australia','AUS','36']},
19{id:'AW',cell:['AW','ARUBA','Aruba','ABW','533']}]
20}


but really get:
 1<div>
 2{
 3page: 1,
 4total: 239,
 5rows: [
 6{id:'AD',cell:['AD','ANDORRA','Andorra','AND','20']},
 7{id:'AE',cell:['AE','UNITED ARAB EMIRATES','United Arab Emirates','ARE','784']},
 8{id:'AF',cell:['AF','AFGHANISTAN','Afghanistan','AFG','4']},
 9{id:'AG',cell:['AG','ANTIGUA AND BARBUDA','Antigua and Barbuda','ATG','28']},
10{id:'AI',cell:['AI','ANGUILLA','Anguilla','AIA','660']},
11{id:'AL',cell:['AL','ALBANIA','Albania','ALB','8']},
12{id:'AM',cell:['AM','ARMENIA','Armenia','ARM','51']},
13{id:'AN',cell:['AN','NETHERLANDS ANTILLES','Netherlands Antilles','ANT','530']},
14{id:'AO',cell:['AO','ANGOLA','Angola','AGO','24']},
15{id:'AQ',cell:['AQ','ANTARCTICA','Antarctica','','']},
16{id:'AR',cell:['AR','ARGENTINA','Argentina','ARG','32']},
17{id:'AS',cell:['AS','AMERICAN SAMOA','American Samoa','ASM','16']},
18{id:'AT',cell:['AT','AUSTRIA','Austria','AUT','40']},
19{id:'AU',cell:['AU','AUSTRALIA','Australia','AUS','36']},
20{id:'AW',cell:['AW','ARUBA','Aruba','ABW','533']}]
21}
22</div>


is there some way to prevent this?