Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

PocketQuery: Dropdown list for only 1 parameter

Chris August 7, 2019

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!

2 answers

1 accepted

1 vote
Answer accepted
Sven Schatter _Lively Apps_
Atlassian Partner
August 8, 2019

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

Chris August 8, 2019

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

Chris August 8, 2019

IncludePage.png

Sven Schatter _Lively Apps_
Atlassian Partner
August 8, 2019

Hi Chris,

that doesn't sound right. Would you be so kind to raise a support ticket at our ServiceDesk for PocketQuery?

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

Best regards,
Sven

Chris August 8, 2019
1 vote
Tim Miller February 19, 2020

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.

Sven Schatter _Lively Apps_
Atlassian Partner
February 20, 2020

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

Tim Miller February 20, 2020

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.  :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events