You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-user@portals.apache.org by Guillaume Bilodeau <gb...@yahoo.com> on 2007/12/07 04:06:23 UTC

ActionRequest and parameter namespacing

Hi all,

This is more a general portlet question but I'm not sure where to post this,
I hope you will be able to help me out.

I have read a few times that one should prepend some elements in a JSP file
with <portlet:namespace /> to avoid name collisions in the final HTML page. 
While this is obvious for JavaScript functions and all "id" attributes of
HTML tags, should this be done for all "name" attributes too?

I'm asking because the behavior I observe in the following isn't what I
expect:

JSP:
	<form method="POST" action="<portlet:actionURL><portlet:param name='action'
value='saveSubscriptions' /></portlet:actionURL>">
			Email:
			<input type="text" name="<portlet:namespace />email"
value="${reference.subscriberEmail}" />
		<input type="submit" name="<portlet:namespace />submit" value="Save" />
	</form>

Portlet:
	public void processAction(ActionRequest request, ActionResponse response) {
		if
("saveSubscriptions".equals(request.getParameter(ACTION_PARAMETER_NAME))) {
		final BasicContentSubscriptionUpdateRequest updateReq = new
BasicContentSubscriptionUpdateRequest();
		updateReq.setSubscriberEmail(request.getParameter("email"));
		// ...
		}
	}

In the portlet, request.getParameter("email") cannot find the "email"
parameter and so returns null.  If I remove the <portlet:namespace/> in the
corresponding JSP tag, request.getParameter("email") does find the parameter
and returns the correct value.  Interestingly, this scenario was working
fine with the IBM Portlet API, where the request was stripping the namespace
from the parameter.

Is this behavior normal?  Won't there be a possible collision if other HTML
tags use the same name?

Cheers,
GB

-- 
View this message in context: http://www.nabble.com/ActionRequest-and-parameter-namespacing-tf4959992.html#a14206018
Sent from the Pluto - User mailing list archive at Nabble.com.


Re: ActionRequest and parameter namespacing

Posted by be...@netsos.com.
It is ok to have more than one element with the same name in an HTML
document.  That's why the DOM function getElementsByName() returns a
collection of nodes and not just a single one like getElementById(). 
Consider the case of checkboxes or radio buttons; all of the controls in a
group should have the same name.  Also, when you're submitting a form,
only the elements within the form tags are included in the query, so even
if you have the same form in two portlets on the same page, only one gets
submitted.  If for some reason you need to namespace the name of a form
element (I've never had to), you will need to use getNamespace when
retrieving the parameter.

-- Ben

>
> Hi all,
>
> This is more a general portlet question but I'm not sure where to post
> this,
> I hope you will be able to help me out.
>
> I have read a few times that one should prepend some elements in a JSP
> file
> with <portlet:namespace /> to avoid name collisions in the final HTML
> page.
> While this is obvious for JavaScript functions and all "id" attributes of
> HTML tags, should this be done for all "name" attributes too?
>
> I'm asking because the behavior I observe in the following isn't what I
> expect:
>
> JSP:
> 	<form method="POST" action="<portlet:actionURL><portlet:param
> name='action'
> value='saveSubscriptions' /></portlet:actionURL>">
> 			Email:
> 			<input type="text" name="<portlet:namespace />email"
> value="${reference.subscriberEmail}" />
> 		<input type="submit" name="<portlet:namespace />submit" value="Save" />
> 	</form>
>
> Portlet:
> 	public void processAction(ActionRequest request, ActionResponse response)
> {
> 		if
> ("saveSubscriptions".equals(request.getParameter(ACTION_PARAMETER_NAME)))
> {
> 		final BasicContentSubscriptionUpdateRequest updateReq = new
> BasicContentSubscriptionUpdateRequest();
> 		updateReq.setSubscriberEmail(request.getParameter("email"));
> 		// ...
> 		}
> 	}
>
> In the portlet, request.getParameter("email") cannot find the "email"
> parameter and so returns null.  If I remove the <portlet:namespace/> in
> the
> corresponding JSP tag, request.getParameter("email") does find the
> parameter
> and returns the correct value.  Interestingly, this scenario was working
> fine with the IBM Portlet API, where the request was stripping the
> namespace
> from the parameter.
>
> Is this behavior normal?  Won't there be a possible collision if other
> HTML
> tags use the same name?
>
> Cheers,
> GB
>
> --
> View this message in context:
> http://www.nabble.com/ActionRequest-and-parameter-namespacing-tf4959992.html#a14206018
> Sent from the Pluto - User mailing list archive at Nabble.com.
>
>