Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sam E
How to pass "request" and Parameters around.
July 29, 2009 6:28 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Hi,

In one JSP file, I use the following coding to call another JSP file (items_list.jsp), and also passing a variable "categoryId" to the items_list.jsp file:

 1
 2
 3                        <%
 4                        String curSection = cat_items_sections[0][0];
 5
 6                        int idx = 0;
 7                        for (String section : cat_items_sections[0]) {
 8                                ShoppingCategory curCategory = (ShoppingCategory)results.get(idx);
 9                                idx++;
10                                curCategory = curCategory.toEscapedModel();
11                                String sectionId = _getSectionId(section);
12                                String sectionJsp = "/html/portlet/shopping/items_list.jsp?categoryId="+ String.valueOf(curCategory.getCategoryId());
13                                System.out.println("sectionJsp: " + sectionJsp);
14                        %>
15
16                            <div class="form-section <%= curSection.equals(section)? "selected" : StringPool.BLANK %>" id="<%= sectionId %>">
17                                        <liferay-util:include page="<%= sectionJsp %>" />
18                                </div>
19
20                        <%
21                        }
22                        %>
23       


In items_list.jsp file, but there there is nothing passed into the items_list.jsp file.
The items_list.jsp file is shown below:
1
2<%@ include file="/html/portlet/shopping/init.jsp" %>
3<%
4ParamUtil.print(request);
5String categoryId = ParamUtil.getString(request, "categoryId");
6System.out.println("categoryId: " + categoryId);
7%>


Your suggestion is much appreciated.
Thanks
Sam
Ed F.
RE: How to pass "request" and Parameters around.
July 29, 2009 8:32 AM
Answer

Ed F.

Rank: Expert

Posts: 280

Join Date: June 26, 2006

Recent Posts

Hey Sam, I could be wrong, but I think the java variables should be included without having to "re-get" them. For example, I just tested:

in first jsp file:
1
2<%
3String temp = "IWonderIfThisWorks";
4%>
5
6<%@ include file="/html/portlet/ext/some_portlet/view2.jsp" %>


in view2.jsp:
1
2<%
3System.out.println(temp);
4%>


and it was detected, so for you I'd try in items_list.jsp just printing or using curCategory and see what happens.
I think the scope should work, but it might just be global variables.

Also if your original jsp file includes init.jsp, depending on what's in your init, I don't think you should need to include it again in items_list

Good luck.
-Ed
Sam E
RE: How to pass "request" and Parameters around.
July 29, 2009 11:02 PM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Ed F.:
Hey Sam, I could be wrong, but I think the java variables should be included without having to "re-get" them. For example, I just tested:

in first jsp file:
1
2<%
3String temp = "IWonderIfThisWorks";
4%>
5
6<%@ include file="/html/portlet/ext/some_portlet/view2.jsp" %>


in view2.jsp:
1
2<%
3System.out.println(temp);
4%>


and it was detected, so for you I'd try in items_list.jsp just printing or using curCategory and see what happens.
I think the scope should work, but it might just be global variables.

Also if your original jsp file includes init.jsp, depending on what's in your init, I don't think you should need to include it again in items_list

Good luck.
-Ed


Hi Ed,

It doesn't work for me.
error is:
 1
 2An error occurred at line: 10 in the jsp file: /html/portlet/shopping/items_test.jsp
 3categoryId cannot be resolved
 47: ParamUtil.print(request);
 58: //categoryId = ParamUtil.getString(request, "categoryId");
 69: System.out.println("------in items_list.jsp After ParamUtil.print(request)");
 710: System.out.println("categoryId: " + categoryId);
 811:
 912: List<String> headerNames = new ArrayList<String>();
1013:


I noticed your "include" is different to mine.
My include is "liferay-util:include":
1
2<div class="form-section <%= curSection.equals(section)? "selected" : StringPool.BLANK %>" id="<%= sectionId %>">
3                    <liferay-util:include page="<%= sectionJsp %>" />
4</div>


Thanks
Sam
Oliver Bayer
RE: How to pass "request" and Parameters around.
July 30, 2009 1:12 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 889

Join Date: February 18, 2009

Recent Posts

Hi,

as a quick solution you can use the portlet session to pass variables to different jsps.
1portletSession.setAttribute("categoryId", 123);
2...
3int catId = (Integer)portletSession.getAttribute("categoryId");

Greets Oli
Sam E
RE: How to pass "request" and Parameters around.
July 30, 2009 4:55 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Oliver Bayer:
Hi,

as a quick solution you can use the portlet session to pass variables to different jsps.
1portletSession.setAttribute("categoryId", 123);
2...
3int catId = (Integer)portletSession.getAttribute("categoryId");

Greets Oli


Hi, thanks for the code.
I just found out use request.setParameter(..) and request.getParameter(..) will do the "trick".

Thanks
Sam