PocketQuery: Dropdown list for only 1 parameter
Asked by Chris:

I have the following pocketquery template that is derived from the "default form template" discussed here: <https://help.scandio.de/documentation/display/PQDOC/Default+PocketQuery+Templates>

My custom template is as follows:

```
<form method="get" class="aui pq-dynamic-parameter-form" action="">

## store GET parameters that are not PQ specific in hidden fields so they don't get lost
#foreach($entry in $req.getParameterMap().entrySet())
#if (!$entry.key.startsWith("pq_") && $PocketQuery.getValueFromMapEntry($entry))
<input type="hidden" name="$entry.key" value="$PocketQuery.getValueFromMapEntry($entry)" />
#end
#end

<button type="submit" class="pq-change-button aui-button aui-style aui-button-primary">Change</button>
#foreach($key in $queryParameters.keySet())
#set($reqKey = "pq_$key")
#set($s=$PocketQuery.getParameterFromRequestOrMacro($key, $req, $queryParameters))
<div>
<label for="$reqKey">$key</label>
<select class="text" type="text" id="$reqKey" name="$reqKey" value="$!req.getParameter($reqKey)" />
<option value="Option1" #if("Option1"=="$s") selected="selected"#end>Option1</option>
<option value="Option2" #if("Option2"=="$s") selected="selected"#end>Option2</option>
</select>
</div>
#end
</form>

$PocketQuery.template("default")
```

This works as expected - it creates a dropdown box with 2 options in it, and a "change" button that I can use to update the query results depending on the option chosen.

However, I have 2 parameters in the query: call them param1 and param2. Right now the dropdown list shows for both parameters. I only want the dropdown list to apply to param1. Param2 will always be set to the page name. How do I tweak the template above to achieve this?

Thanks for your help!


Answers:
author: Sven Schatter _Lively Apps_
body: Hi Chris! :)

The reason that both parameters get a *\<select\>* is basically this:

```
#foreach($key in $queryParameters.keySet())
  ...
#end
```

You are looping through all of the available *$queryParameters* . So instead of looping through all parameters with a *#foreach* loop, you could simply render the one parameter manually:

```
#set($key = "param1")
#set($reqKey = "pq_$key")
#set($s=$PocketQuery.getParameterFromRequestOrMacro($key, $req, $queryParameters))
<div>
  <label for="$reqKey">$key</label>
  <select class="text" type="text" id="$reqKey" name="$reqKey" value="$!req.getParameter($reqKey)">
    <option value="Option1" #if("Option1"=="$s") selected="selected"#end>Option1</option>
    <option value="Option2" #if("Option2"=="$s") selected="selected"#end>Option2</option>
  </select>
</div>
```

I hope this makes sense! :)

Howeeeeeveeer... You said that *param2* is always set to the pagename. This sounds very much like you should use [wildcards](https://help.scandio.de/documentation/display/PQDOC/Queries#Queries-UsingWildcardsforParameters) instead of a second parameter.

So let's say your Query looks like this:

```
SELECT *
FROM something
WHERE x = :param1
AND pageName = :param2
```

With a wildcard you could do this instead:

```
SELECT *
FROM something
WHERE x = :param1
AND pageName = :@page
```

*:@page* will be replaced with the pagename automatically and will not show up as a second parameter. I think in your case this is the cleaner solution. :)

Let me know if this helps!

Best regards,  
Sven

comments: author: Chris
body: Thanks Sven, both examples are very helpful and I was able to get things working! I have one additional question now that perhaps you could also help me with...

I have a page, let's call it *page1* , that uses the solution you described above. So it is a table driven by pocketquery results and has a drop down list to dynamically change the results in the table based on what is selected. *Page1* is also shown on *page2* , using the **include page** macro. The problem is that the only thing I see on *page2* is the change button and an empty dropdown list - the table and dropdown values from *page1* do not appear. Is there any way around this?

I'm able to show the expected results on *page2* if I remove the dropdown list and replace it with a textbox, but this doesn't meet our requirements. Attached is a picture of what I see on *page2.*

Thanks for your help,  
Chris


author: Chris
body: ![IncludePage.png](https://community.atlassian.com/t5/image/serverpage/image-id/62770i0E675DBDB7AFE445/image-size/large?v=v2&px=999 "IncludePage.png")


author: Sven Schatter _Lively Apps_
body: Hi Chris,

that doesn't sound right. Would you be so kind to **[raise a support ticket at our ServiceDesk for PocketQuery](https://help.scandio.de/servicedesk/customer/portal/5)**?

Be sure to include all details such as template, macro parameters and query statement and we will solve this together. :)

Best regards,  
Sven


author: Chris
body: Thanks, created a support ticket: <https://help.scandio.de/servicedesk/customer/portal/5/PQ-276>


author: Tim Miller
body: Just for those that run across this solution in the future and find it not working correctly. There is a mistake in the following line.

```
<select class="text" type="text" id="$reqKey" name="$reqKey" value="$!req.getParameter($reqKey)" />
```

The / at the end shouldn't be there because it is not the closing of the select tag. That is down below all of the options specified.

comments: author: Sven Schatter _Lively Apps_
body: Oops! Thanks for pointing that out. I also removed the extra slash from I own answer so people blindly copy/pasting won't fall for it. I hope it hasn't caused you too much trouble!

Cheers,  
Sven


author: Tim Miller
body: No Problem Sven. It only tripped me up for a minute or two. Was easy to see once I inspected the output. Thank goodness for Chrome Developer Tools. :)


Tags: pocketquery