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

Recommended Answers

All 21 Replies

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.

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>";

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

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"?

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.

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)

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

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>";

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.

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.

Any suggestions??

Why can't you access form fields in the portlet?

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

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>";

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>";

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


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

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

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.

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?

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

What link are you referring to?

A link to the page you are talking about, that is creating that error.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.