cancel
Showing results for 
Search instead for 
Did you mean: 

pass get args from page to webscript

viru0
Champ in-the-making
Champ in-the-making
Hello! I have a page with several webscripts on it.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<page>
   <id>scans</id>
   <title>Сканы</title>
   <template-instance>scans</template-instance>
   <authentication>none</authentication>
   <components>
        <component>
            <region-id>center</region-id>
            <url>/scans/upload</url>
        </component>
        <component>
            <region-id>listbox</region-id>
            <url>/scans/list</url>
        </component>
    </components>
</page>

How can i pass page "GET" args (example ./scans?tag=mech)
only to second web script?
2 REPLIES 2

ddraper
World-Class Innovator
World-Class Innovator
Hi,

You should be able to access the request parameters in both the WebScript JavaScript controller and FreeMarker template by using "page.url.args" e.g. for your example parameters you can use:

page.url.args.tag

And you can iterate over all the request parameters in the FreeMarker template as follows:

<#list page.url.args?keys as key>
   ${key} = ${page.url.args[key]}
</#list>

It won't be possible to prevent them from being available to all WebScripts within the page as they are specific to the page. Is there any particular reason why you don't want one of the WebScripts to have access to the request parameters?

Regards,
Dave

erikwinlof
Confirmed Champ
Confirmed Champ
Hi, viru.

It is possible if both webscripts use the "args" object (rather than  page.url.args to get their properties/parameters).
Then you can make use the following config where you explicitly bind in the property to only one of the webscripts.

<page> 
   <id>scans</id>
   <title>Сканы</title>
   <template-instance>scans</template-instance>
   <authentication>none</authentication>
   <components>
        <component>
            <region-id>center</region-id>
            <url>/scans/upload</url>
            <properties>
               <tag>{tag}</tag>
            </properties>
        </component>
        <component>
            <region-id>listbox</region-id>
            <url>/scans/list</url>
        </component>
    </components>
</page>


upload.get.js

var tag = args.tag;

upload.get.html.ftl
${args.tag}

Try to always use the "args" object in your webscripts since that approach gives you full control of your webscript's parameters.