PDA

View Full Version : How to use URL parameters in ExtJS view?



Geziefer
29 Nov 2010, 7:56 AM
Hello,

I have an index.jsp which besides other things contains a script tag calling a js file contructing an ExtJS panel.
Now, if I want to do something in the view depending on parameters in the URL, how would I be able to access them in the js file (e.g. set a combo box value to the id in an url parameter myId)?

Regards,
Alex

Condor
29 Nov 2010, 8:06 AM
You can't access the parameters in the the .js url. You can only access the ones in the .jsp url.

(if you changed your .js to a .jsp then you would be able to do this on the server)

Geziefer
29 Nov 2010, 8:19 AM
I'm not completely sure, what you meant by ".js url" and ".jsp url" - let me rephrase the question a bit:

I have a jsp file which should be accessable by a parameter, e.g. http://mypath/my.jsp?myId=10

Now I need to set this myId as a value of a combo box in my ExtJS panel - what can I do to achieve that?

Would I need to put the javascript code of the given panel directly in the jsp and use some ugly jsp substitution at the point where the combo value is set or is there a way of using just a script tag in the jsp to a separate my.js file and use some sort of shared object which is set in the jsp and read in the js file?

Condor
29 Nov 2010, 8:23 AM
You need a small bit of javascript in your .jsp, e.g.

<script type="text/javascript">
myId = <%= request.getParameter('myId') %>;
</script>
<script type="text/javascript" src="myscript.js"></script>
(now myscript.js can use the global 'myId' variable)

Condor
29 Nov 2010, 8:24 AM
Or, depending on how you call your .jsp, you could use:

var params = Ext.urlDecode(location.search.substr(1));
var myId = params.myId;
Disclaimer: Completely untested code!