Vu NG
Vu NG

Reputation: 290

How to pass input text value as portlet param

I have a portlet page:

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

<portlet:resourceURL var="resourceUrl">
    <portlet:param name="startDate" value="" />
</portlet:resourceURL>

<input id="startdateexportaging" type="text" />

<a style="font-size: 15px;" href="${resourceUrl}" >URL</a>

How to pass the content of startdateexportaging as portlet param startDate when clicking the link with resourceUrl?

Upvotes: 0

Views: 1545

Answers (1)

Tobias Liefke
Tobias Liefke

Reputation: 9022

You could use an onclick handler to add the content to the URL as soon the link is clicked. But that would be cumbersome, error prone and not necessary.

Instead you should add your input to a form and define the URL as action parameter:

<aui:form action="<%= resourceUrl.toString() %>" method="get"> 
    <aui:input name="startDate" type="text" />
<aui:button value="Download" type="submit" />
</aui:form>

(if you don't use AUI - you can use simple HTML tags as well)

Another advantage of this solution: A button instead of a link makes it easier for the user to understand that the content from the text field is submitted. Compare it with the use of links and buttons here on SO - if you enter some information you have to hit a button.

And it is easier for search engines to parse the website, as those try to follow links - but ignore buttons.

Upvotes: 1

Related Questions