Combination View Flat View Tree View
Threads [ Previous | Next ]
RE: "from DB to simple UI" question 2
toggle
Copied from EmForge Portal forum (http://www.emforge.net/web/emforge-portal/forums/-/message_boards/message/178629)

Finally, I get the job done, the JSP was able to be called from the view.jsp, I have to inherited the JSPPortlet, that is the key.
But, still, I have couple of more questions.

1. from view.jsp, I like to add the pet_action.jsp, and it contain two icons, one for edit, another one for delete, but it didn't work, from pet_action.jsp, I add the JSP for pet_edit.jsp, inside the pet_edit.jsp, I use the follow code

1ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
2Pet pet = (Pet)row.getObject();


but the second line throw the exception, is that means this can not be called from pet_edit.jsp

2. I like to add the edit and delete icon for each pet, where I can find the hint for the code, I like to use liferay UI tag as much as possible, so it can fit in the main theme.

3. still, from doView class, follow the code, I can not get the right petid, it always return 0, which is kind of surprise.

I am eager to see the second part of this tutorial, this is one of the best liferay portal tutorial I can find, hope it can keep it update.

Thanks.
Flag Flag
RE: "from DB to simple UI" question 2
7/22/10 9:35 PM as a reply to Alexey Kakunin.
Hi!

Alexey Kakunin:
Copied from EmForge Portal forum (http://www.emforge.net/web/emforge-portal/forums/-/message_boards/message/178629)

Finally, I get the job done, the JSP was able to be called from the view.jsp, I have to inherited the JSPPortlet, that is the key.
But, still, I have couple of more questions.

1. from view.jsp, I like to add the pet_action.jsp, and it contain two icons, one for edit, another one for delete, but it didn't work, from pet_action.jsp, I add the JSP for pet_edit.jsp, inside the pet_edit.jsp, I use the follow code

1ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
2Pet pet = (Pet)row.getObject();




Looks a little bit strange why you need it in pet_edit.jsp
Actually, to add actions into each row with pet you need to do on view.jsp something like:

 1
 2List<ResultRow> resultRows = searchContainer.getResultRows();
 3    for (int i=0; i < pets.size(); i++) {
 4        Item pet = pets.get(i);
 5        ResultRow row = new ResultRow(pet, pet.getItemId(), i);
 6
 7        PortletURL petURL = renderResponse.createRenderURL();
 8        petURL.setWindowState(WindowState.MAXIMIZED);
 9        petURL.setParameter("pet_id", String.valueOf(pet.getItemId()));
10        petURL.setParameter("redirect", com.liferay.portal.util.PortalUtil.getCurrentURL(request));
11        row.addText(pet.getName(), petURL.toString());
12       
13       
14        row.addJSP("/pet_image.jsp", application, request, response);
15        row.addText(String.valueOf(pet.getPrice()));
16
17            row.addJSP("/pet_action.jsp", application, request, response);
18
19        resultRows.add(row);
20    }   

(Don't forget to add one more column into headers of table)

and in pet_actions.jsp some code like

 1
 2<%@ page import="com.liferay.portal.kernel.dao.search.ResultRow" %>
 3<%@ page import="com.liferay.portal.kernel.util.WebKeys" %>
 4<%@ page import="petcatalog.model.Item" %>
 5
 6<%
 7ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
 8
 9Item pet = (Item)row.getObject();
10String petId = String.valueOf(pet.getItemId());
11%>
12
13<portlet:renderURL var="editURL">
14            <portlet:param name="jspPage" value="/pet_edit.jsp" />
15            <portlet:param name="redirect" value="<%= currentURL %>" />
16            <portlet:param name="petid" value="<%= petId %>" />
17</portlet:renderURL>
18
19<liferay-ui:icon image="edit" url="<%= editURL %>" />
20
21<portlet:actionURL name="deletePetItem" var="deleteURL">
22            <portlet:param name="redirect" value="<%= currentURL %>" />
23            <portlet:param name="petid" value="<%= petid %>" />
24</portlet:actionURL>
25
26<liferay-ui:icon image="delete" url="<%= deleteURL %>" />


This code should also answer how to add edit/delete buttons, as well as how to pass petid into pet_edit.jsp
To delete pet you will need to add action method into PetPortlet like:

1
2    public void deletePetItem(ActionRequest request, ActionResponse response) throws Exception {
3        Long petId = ParamUtil.getLong(request, "petId");
4
5        // code to remove pet
6
7    }


Alexey Kakunin:

but the second line throw the exception, is that means this can not be called from pet_edit.jsp

2. I like to add the edit and delete icon for each pet, where I can find the hint for the code, I like to use liferay UI tag as much as possible, so it can fit in the main theme.


Alexey Kakunin:

3. still, from doView class, follow the code, I can not get the right petid, it always return 0, which is kind of surprise.

I am eager to see the second part of this tutorial, this is one of the best liferay portal tutorial I can find, hope it can keep it update.

Thanks.


Unfortunatelly too busy, but I hope to update tutorial to follow Liferay 6 and Liferay IDE soon, as well as extend it (for example cover these questions about actions)
Flag Flag