0

Hi I am looking to set the value of <portlet:param> tag using java script.

Here is my existing code

<form name="frmname" method="post"
	enctype="multipart/form-data" action="<portlet:actionURL><portlet:param name="page" value="mainview"/></portlet:actionURL>">

And I am setting the value of the portlet:param tag by calling the following javascript on the page load event.

function callingonpageload()
{	
	var gettag = document.getElementById ("frmname:page");
	gettag = window.opener.document.getElementById("Baseline:EngineModel").value;
	alert("Selected Value"+gettag.value);
}

This function is triggered and the the alert box output is following.
selected valueundefined

3
Contributors
21
Replies
22
Views
5 Years
Discussion Span
Last Post by babbu
0

Javascript is client side code. It will only update the output of the servlet, the final HTML that is delivered to the browser.

Those portlet tags are happening server side prior to rendering the html.

If you want to update via javascript, look at the final outputted HTML and update that with the javascript, not the jsp code.

0

ok Ive modified my code.

var val = window.opener.document.getElementById("Baseline:EngineModel").value;
document.frmname.action = "<portlet:actionURL><portlet:param name='page' value=" + val.value + "/></portlet:actionURL>";
document.frmname.submit();

this returns the value as val.value and not the actual value present in the variable.
any suggestions

0

If you look at the HTML (View Source in the browser) after it's rendered, do you see the name/ID of that field as "Baseline:EngineModel"?

0

Yes I do see that and that is fetching the needed value.
My problem lies in the subsequent lines of code.
The variable val gets the proper value before it is being used. Its just that I am not able to store that value where needed.

0

Oh, ok I see what you're saying.

Have you tried just:

document.frmname.action = "<portlet:actionURL><portlet:param name='page' value=" + val + "/></portlet:actionURL>";

(without the .value)

0

Yes I've tried that as well. It stores "+ val +" and not the actual value inside it.

0

Somehow js is not seeing your quote closing and treating the whole thing like a string.

You might try this just to see what difference it makes (escaping the single quotes):

var val = window.opener.document.getElementById("Baseline:EngineModel").value;
    document.frmname.action = "<portlet:actionURL><portlet:param name=\'page\' value=" + val.value + "/></portlet:actionURL>";
    document.frmname.submit();

For what it's worth, I've never done it that way and have never really seen other people do it that way. In my circles the most common way to do that is to have a hidden form field and then set the value of the hidden form field in the javascript and then submit. The values will then come in that way instead of having to manually jigger the action url.

0

I would love to set it using hidden form field, but the problem is I am not able to access them in the processAction method of FacesPortlet.

0

I don't know how that is done. Tried a lot of this. request.getParameter, request.getAttributes, session, all returning null values.
Please advice.

0

hi,
did you try eval() ?

var val = window.opener.document.getElementById("Baseline:EngineModel").value;
document.frmname.action = "<portlet:actionURL><portlet:param name='page' value=" + eval(val.value) + "/></portlet:actionURL>";
document.frmname.submit();

or may be

var val = window.opener.document.getElementById("Baseline:EngineModel").value;
alert(val.value); /*or similar trick just to check that whether it comes up till here properly as desired ... */
document.frmname.action = "<portlet:actionURL><portlet:param name='page' value=" + val.value + "/></portlet:actionURL>";
document.frmname.submit();

by the way just noticed ... when you call

var val = window.opener.document.getElementById("Baseline:EngineModel").value;

it already is taking a value right? then still again you are doing a

val.value

property ... (may be I am being foolish here ... but just trying to help... :P)

Edited by Rahul V S: n/a

0

I'll give eval a try. Rest everything suggested by you has been tried unsuccessfully.
:(

0

Another thing to try is using a variable name other than val. val is a function in javascript so that might be screwing you up. Use something unique.

0

I tried using the eval functtion as suggested above. But it throws a javascript error.

Message: Expected ';'
Line: 61
Char: 196
Code: 0

Don't know where the error is.
I tried using it as suggested by Rahul

document.frmname.action = "<portlet:actionURL><portlet:param name='page' value=" + eval(val.value) + "/></portlet:actionURL>";

Any idea where I am going wrong?

0

If you could post a link we'd probably be able to figure it out pretty quickly.

0

It is not yet hosted on a server. I am working on my local system.

0

I found a workaround and I don't need to set the value using javascript. Thanks everyone for your help and time

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.