You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by "Tiwari, Sunil Kumar" <c_...@qualcomm.com> on 2006/01/09 19:22:05 UTC

How to use a VTL variable in a javascript?

Hi All,

How to assign the value of a VTL variable to a form element in
javascript?
For example: I have a variable $test="somevalue".
I want it to assign it to some form element say an input text element
using javascript. How can I do it?

Thanks,
Sunil

-----Original Message-----
From: Tiwari, Sunil Kumar [mailto:c_stiwar@qualcomm.com] 
Sent: Friday, January 06, 2006 9:35 PM
To: Jetspeed Users List
Subject: RE: Re: How to create a new skin and add custom mode to it
injetspeed2?




-----Original Message-----
From: news on behalf of Aaron Evans
Sent: Fri 1/6/2006 11:41 AM
To: jetspeed-user@jakarta.apache.org
Subject:  Re: How to create a new skin and add custom mode to it
injetspeed2?
 
Tiwari, Sunil  Kumar <c_stiwar <at> qualcomm.com> writes:

> The search box request must be passed to a servlet.
> I have created a .vm file for this where I have a html form tag and I
> try to call an action on it but somehow it doesn't work.
> 
> Any ideas?

Sunil,
If you are simply trying to post to a servlet outside of jetspeed (but
on the 
same server), just make the URL of the action the URI of the servlet.
That is, 
something like:

/<servlet_application_context>/<URI_that_maps_to_your_servlet>

Just remember that the user will then leave the portal and be brought to
the
response of your servlet.  Further, unless you have tomcat SSO turned
on, you 
will lose the identity of the user that has invoked the servlet.

What would probably be better is to turn your search servlet into a
portlet and
then figure out how to have the search form (in the header) trigger your

portlet. Let me know when you figure that out! :)

Aaron,

Thanks for your advise and I tried out your suggestion and it worked
perfectly!
I am simply trying to post to a servlet outside of jetspeed.

But I have a query here which doesnt concern with servlet but to
velocity template and java script.

Suppose the request url is generated dynamically i.e the action can be
triggered to different servlets depending on some parameter.

Now I have a search box and the search string can be posted to google,
yahoo or some custom servlet(provided as radio buttons).

I have a form element in my jsp.

<form name="form1" action="javascript:null"
onSubmit="javascriptFunction(this.form);">

In the javascript function, I find out which radio button was selected
and accordingly specify the form.action="some url". The url is a
complete one like http://google.com

If the user selects the custom servlet radio button then I assign the
form.action= <%=servletURl%> (servletUrl is computed in a jsp scriplet)

This code works fine for a websphere theme.

I moved it to Jetspeed by making it a .vm file and it works fine except
for the servlet case.
The problem is that it doesnt recognise <%=servletURl%> within the
javascript. Its obvious so I changed it accordingly using VTL variable.

I store the servletUrl in $url and then form.action=$url in javascript.
It didnt work. I tried form.action=#url and #$url but I knew it wldnt
work.

The question is how to use VTL variable within javascript??

You must be wondering why I have explained all this instead of asking
directly, but I guess it makes the picture clear.

I think there must be some way to do it and if there is no way then how
to get a work around for it.

Thanks!
-Sunil


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


RE: How to use a VTL variable in a javascript?

Posted by Scott T Weaver <sc...@binary-designs.net>.
var myJsVar = '$test';

That's it!

Regards,
-Scott

> -----Original Message-----
> From: Tiwari, Sunil Kumar [mailto:c_stiwar@qualcomm.com]
> Sent: Monday, January 09, 2006 1:22 PM
> To: Jetspeed Users List
> Subject: How to use a VTL variable in a javascript?
> 
> Hi All,
> 
> How to assign the value of a VTL variable to a form element in
> javascript?
> For example: I have a variable $test="somevalue".
> I want it to assign it to some form element say an input text element
> using javascript. How can I do it?
> 
> Thanks,
> Sunil
> 
> -----Original Message-----
> From: Tiwari, Sunil Kumar [mailto:c_stiwar@qualcomm.com]
> Sent: Friday, January 06, 2006 9:35 PM
> To: Jetspeed Users List
> Subject: RE: Re: How to create a new skin and add custom mode to it
> injetspeed2?
> 
> 
> 
> 
> -----Original Message-----
> From: news on behalf of Aaron Evans
> Sent: Fri 1/6/2006 11:41 AM
> To: jetspeed-user@jakarta.apache.org
> Subject:  Re: How to create a new skin and add custom mode to it
> injetspeed2?
> 
> Tiwari, Sunil  Kumar <c_stiwar <at> qualcomm.com> writes:
> 
> > The search box request must be passed to a servlet.
> > I have created a .vm file for this where I have a html form tag and I
> > try to call an action on it but somehow it doesn't work.
> >
> > Any ideas?
> 
> Sunil,
> If you are simply trying to post to a servlet outside of jetspeed (but
> on the
> same server), just make the URL of the action the URI of the servlet.
> That is,
> something like:
> 
> /<servlet_application_context>/<URI_that_maps_to_your_servlet>
> 
> Just remember that the user will then leave the portal and be brought to
> the
> response of your servlet.  Further, unless you have tomcat SSO turned
> on, you
> will lose the identity of the user that has invoked the servlet.
> 
> What would probably be better is to turn your search servlet into a
> portlet and
> then figure out how to have the search form (in the header) trigger your
> 
> portlet. Let me know when you figure that out! :)
> 
> Aaron,
> 
> Thanks for your advise and I tried out your suggestion and it worked
> perfectly!
> I am simply trying to post to a servlet outside of jetspeed.
> 
> But I have a query here which doesnt concern with servlet but to
> velocity template and java script.
> 
> Suppose the request url is generated dynamically i.e the action can be
> triggered to different servlets depending on some parameter.
> 
> Now I have a search box and the search string can be posted to google,
> yahoo or some custom servlet(provided as radio buttons).
> 
> I have a form element in my jsp.
> 
> <form name="form1" action="javascript:null"
> onSubmit="javascriptFunction(this.form);">
> 
> In the javascript function, I find out which radio button was selected
> and accordingly specify the form.action="some url". The url is a
> complete one like http://google.com
> 
> If the user selects the custom servlet radio button then I assign the
> form.action= <%=servletURl%> (servletUrl is computed in a jsp scriplet)
> 
> This code works fine for a websphere theme.
> 
> I moved it to Jetspeed by making it a .vm file and it works fine except
> for the servlet case.
> The problem is that it doesnt recognise <%=servletURl%> within the
> javascript. Its obvious so I changed it accordingly using VTL variable.
> 
> I store the servletUrl in $url and then form.action=$url in javascript.
> It didnt work. I tried form.action=#url and #$url but I knew it wldnt
> work.
> 
> The question is how to use VTL variable within javascript??
> 
> You must be wondering why I have explained all this instead of asking
> directly, but I guess it makes the picture clear.
> 
> I think there must be some way to do it and if there is no way then how
> to get a work around for it.
> 
> Thanks!
> -Sunil
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org