Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails multiple g:if test for more than one condition

Tags:

grails

I have a select box of TYPES that each type has their own PARAMETERS. The TYPES select box will fire off some AJAX that calls a template and renders PARAMETER select boxes on my view. The Parameters are made up of name:value pairs, thus every name can have many values.

Some parameters need multiple='true' for the user to select multiple values for each name, while other parameters need to be restricted to only one choice.

In my gsp page I have a bunch of these:

    <g:if test="${it?.getKey().toString().equals('PARAMETER_A')}">
      <td><g:select multiple="true" optionKey="id" optionValue="value" name="sampleParameters" id="parameter" value="${params?.sampleParameters}" from='${it?.getValue().sort()}'></g:select></td>
    </g:if>
    <g:if test="${it?.getKey().toString().equals('PARAMETER_B')}">
      <td><g:select multiple="true" optionKey="id" optionValue="value" name="sampleParameters" id="parameter" value="${params?.sampleParameters}" from='${it?.getValue().sort()}'></g:select></td>
    </g:if>

My issue is that I have 6 parameters for one particular TYPE that need to select multiple values, the rest do not. Rather than explicitly type out as above, is there a way that I can test for more than one thing in a g:if statement like you can in java? such as:

if(something.equals(PARAMETER_A) || something.equals(PARAMETER_B))

etc.

Is there a way to do something similar to java's approach in groovy?

like image 717
Universitas Avatar asked Aug 03 '12 19:08

Universitas


1 Answers

Grails g:if just uses groovy in its test attribute. So to answer your question, yes:

<g:if test="${something.equals(PARAMETER_A) || something.equals(PARAMETER_B)}">
</g:if>
like image 135
Gregg Avatar answered Sep 28 '22 13:09

Gregg