5
votes

So I'm having some trouble figuring out how to handle navigation in liferay. I'm new to jsp, portlets, and liferay, but I think I've exhausted all of the documentation looking for an answer.

I'm looking for a way to submit an html form and set render parameters with the fields. I would like to have URLs that work with normal browser navigation, and bookmarkable urls. I have figured out a way to do it by using javascript to update an already declared renderurl with new values from the form, but I'm trying to figure out a cleaner way of doing so.

Right now I've tried a few methods.. using this page

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portal.kernel.util.Validator" %>
<%@ page import="javax.portlet.PortletPreferences" %>

<portlet:defineObjects />


<%
    PortletPreferences prefs = renderRequest.getPreferences();
    String search = ParamUtil.getString(renderRequest, "search");
%>

<portlet:renderURL var="viewURL">
<portlet:param name="jspPage" value="/view.jsp" />
</portlet:renderURL>

<aui:form action="<%= viewURL %>" method="post">
     <aui:input label="search" name="search" type="text" value="<%=search %>" />
     <aui:button type="submit" />
</aui:form>

Using post, I'd get the resulting url:

http://localhost:8080/web/10157/home?p_p_id=search_WAR_searchportlet_INSTANCE_Kt9C&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_search_WAR_searchportlet_INSTANCE_Kt9C_jspPage=%2Fview.jsp

If I change the form to get, then I get this url:

http://localhost:8080/web/10157/home?_search_WAR_searchportlet_INSTANCE_Kt9C_search=123

But using a renderURL with the parameter set, I'd get this, which is a combination of what both post and get would return:

http://localhost:8080/web/10157/home?p_p_id=search_WAR_searchportlet_INSTANCE_Kt9C&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_search_WAR_searchportlet_INSTANCE_Kt9C_jspPage=%2Fview.jsp&_search_WAR_searchportlet_INSTANCE_Kt9C_search=123

So for now, I can either use a form with post, and ParamUtil.getString will recognize the data, but the link will not be bookmarkable, or I could use a form with get, leaving information in the url, but I cannot get ParamUtil to recognize the data. Even if I could get the data to be recognized using a get form, I really don't want to use that, as the parameter will not be preserved if I'm doing any submitting from forms in other portlets. From what I understand, RenderURLs preserve these things.

Pardon me if I'm completely off on these things, please. I am new to jsp, portlets, and liferay and rather lost on how I'm supposed to do a lot of these things.

2
It seems that your question lacks a bit of clarity as to what you want to acheive. We somehow get what the problem is, but I am not sure if I can put you back on the rails you want.Ar3s

2 Answers

1
votes

as u need to use

<portlet:actionURL>

for handling form submit action.....

1
votes

What you first must understand (and which took me a lot of time) is the portlet workflow.

A portlet either renders itself of process her action.

When a the action of a portlet is called, it'll automatically be requested to execute its render method as well (after its action).

As a matter of facts

  • If you want to just display a portlet
    • renderUrl
  • If you want to send informations to your portlet
    • actionUrl
  • if you to modify your portlet configuration/preferences
    • configurationUrl

This is purely theoretical as you can mess all this workflow up. Still I would not recommend you to do this for multiple reasons like :

  • it breaks maintainability
  • you won't be able to use some built in logics and native workflows that are really powerfull
  • you give yourself more responsibility for when it'll crash.

Now, if you want to get your form's fields values in a process action, they'll be available as request parameters.

If tou want to get portlet preferences, I recommend you read some about portlet configuration on the liferay wiki.

You also seem to want to be able to send action-requests or render requests from a portlet to another.
Always keep in mind that liferay-portlet:actionURL tag and liferay-portlet:renderURL tag both have an attribute portletName that allow you to specify a portlet other than the current one.

Hope this helps. Do not hesitate to ask if I'm not clear enough or if this raises other questions.