Foros de discusión

How to pass parameter from Button to DoView method

Luca kk, modificado hace 12 años.

How to pass parameter from Button to DoView method

Expert Mensajes: 284 Fecha de incorporación: 7/12/10 Mensajes recientes
Hi all,
in my view.jsp I have this simple button:

<input name="page1" type="button" class="yt-uix-button-content" value="1">


I want to pass parameter "value=1" to "DoView" method whe I click on button.

How can I do?

Thanks in advance.
thumbnail
David H Nebinger, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Well, I don't know what framework you're using, but it should be available as part of the parameters for the request, although it would also be namespaced.
Luca kk, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Expert Mensajes: 284 Fecha de incorporación: 7/12/10 Mensajes recientes
Hi David,
thanks for reply.

You say that:

renderRequest.getParameter("value");


returns "1"?
thumbnail
David H Nebinger, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Well, you can try that to be sure, but the parameter might also be namespaced, such as "portlet_myportlet_WAR_myportlet:value". You can grab the list of parameter names and dump it to the log to see what exactly you have to work with...
Luca kk, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Expert Mensajes: 284 Fecha de incorporación: 7/12/10 Mensajes recientes
I tried:

request.getParameter("[b]portlet_myPortlet_WAR_myPortlet:value[/b]")


but it doesn't work!
thumbnail
David H Nebinger, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Because the "portlet_myportlet..." thing was just an example to demonstrate how the parameter might be namespaced. Like I said, you'll need to enumerate the parameter names to find the one that you're looking for. Or it might be handled by your particular framework (which you didn't mention).

If the parameter is namespaced, then you will typically iterate through the parameters finding the one that ends with ":value".

But all of this is assuming that you're working at an extremely low level... Aren't you using some sort of framework or something in your portlet development to alleviate having to manage all of these details yourself?
Luca kk, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Expert Mensajes: 284 Fecha de incorporación: 7/12/10 Mensajes recientes
I use no particular framework.
I developed the portlet with Net Beans, as a simple web application
and deployed it in Liferay.
thumbnail
David H Nebinger, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
As a web application or as a portlet application? Even these will have a different result...

Honestly Luca, it will end up being a heck of a lot easier for you if you identify some framework to leverage, whether it's JSP/Struts2, Spring Web Flow, JSF, Vaadin, etc. Otherwise you're going to spend lots of time down in these kinds of details where a framework will keep you above most of the gore...
Luca kk, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Expert Mensajes: 284 Fecha de incorporación: 7/12/10 Mensajes recientes
Ok,
I'm using JSP framework.
thumbnail
Jitendra Rajput, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Liferay Master Mensajes: 875 Fecha de incorporación: 7/01/11 Mensajes recientes
You mean to say you are not getting any form parameter in controller ?

Can you please post yr JSP for more details ..
Luca kk, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Expert Mensajes: 284 Fecha de incorporación: 7/12/10 Mensajes recientes
My jsp is:

&lt;%@page contentType="text/html"%&gt;
&lt;%@page pageEncoding="UTF-8"%&gt;

&lt;&lt;%@ page import="javax.portlet.*"%&gt;
&lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%&gt;

<portlet:defineobjects />
&lt;%PortletPreferences prefs = renderRequest.getPreferences();%&gt;
<link rel="stylesheet" type="text/css" href="/html/irma/css/video-list.css">
<link rel="stylesheet" type="text/css" href="/html/irma/css/yt_uix_button.css">

<b>

        <input name="page1" type="button" class="yt-uix-button-content" value="1">

</b>
thumbnail
Jitendra Rajput, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Liferay Master Mensajes: 875 Fecha de incorporación: 7/01/11 Mensajes recientes
Where is your form element ? How you are submitting form ?..
Luca kk, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Expert Mensajes: 284 Fecha de incorporación: 7/12/10 Mensajes recientes
Hi Jitendra,
the problem is the action attribute.
What do I put in the action to pass parameter "value=1" to the doView method?

The form that I use is:



Regards,
Luca
thumbnail
Jitendra Rajput, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Liferay Master Mensajes: 875 Fecha de incorporación: 7/01/11 Mensajes recientes
<portlet:actionURL name="nameOfAction" >
<portlet:param name="user" value="myname" />
</portlet:actionURL>
thumbnail
Jesús Salinas, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

New Member Mensajes: 15 Fecha de incorporación: 1/02/10 Mensajes recientes
Hello,

If you need to pass parameter from a form to a doView method, you have to do something like this:
- JSP Page:

<portlet:renderurl var="var1">
       <portlet:param name="param1" value="value1">
</portlet:param></portlet:renderurl>

<form action="<%=var1 %>" ...>
        ...
</form>


And later, in Java code, you could get this param:


...
String param1 = renderRequest.getParameter("param1");
...
thumbnail
David H Nebinger, modificado hace 12 años.

RE: How to pass parameter from Button to DoView method

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
renderUrls are not the same as actionUrls...