Help with Jelly TEST= please

tobrien
Kilo Guru

Hi All,

We're on Helsinki ...

I've got a UI PAGE attempting to populate a SELECT; choosing one entry to be SELECTED...

<select name="selectList" id="selectList" onchange="getSelectListOptionValue(this)">

  <j:while test="${jvar_list.next()}">

            <j:set var="jvar_value" value="${jvar_list.getValue('u_vendor_name')}"/>

            <j:choose>

            <j:when test="$[jvar_value== searchBy]">

                      <option value="${jvar_value}" selected="selected">${jvar_value}</option>

            </j:when>

            <j:otherwise>

                      <option value="${jvar_value}">${jvar_value}</option>

            </j:otherwise>

            </j:choose>

  </j:while>

</select>

The value of 'searchBy' is known to be a valid case of one of the jvar_value

The line ==>

        <j:when test="$[jvar_value== searchBy]">

Is never found to come true though ALERTs have show that jvar_value and searchBy have the same value for one record... I've got a test suite of 2 records.

Any ideas?

The line== searchBy]">

1 ACCEPTED SOLUTION

Interestingly, it looks like Jelly will not support a combination of a jelly variable (jvar_value) and a javascript variable (searchBy) in the test condition. It seems to work if both are jelly variables or both are javascript variables.



You also need to fix the syntax in the test condition to use curly braces {} instead of box brackets [] since this is to be evaluated in phase 1 as mentioned by Chuck above.



One way of fixing this would be to use a g:evaluate or a j:set to set the value of searchBy in a jelly var (jvar_searchBy) and change the test condition in line 1 above to be:



<j:when test="${jvar_value == jvar_searchBy}">



Hope that helps.


PS: Please hit "Correct", "Helpful" or "Like" depending on the impact of the response.


View solution in original post

6 REPLIES 6

Chuck Tomasi
Tera Patron

The square brackets are phase 2, you'll want to change that first. Try this:



<j:when test="${jvar_value} eq 'searchBy'">


Thanks, Chuck, but no joy...



And, since the 'searchBy' is also a javascript variable, I also tried



<j:when test="${jvar_value} eq ${searchBy}">



Still never matches.



Did you validate that ${jvar_value} has a value? You should be able to see this with a <g:breakpoint /> with debugging turned on to inspect your variables.


Actually I am using it both the normal and "selected" cases of adding the option just for that purpose ... I've even used the JVAR_VALUE and SEARCHBY interchangeably in lines 2 and 5 just to ensure they BOTH have values and that's how I know that they have EQUAL values for the one row I expect to set that option to SELECTED.




  1. <j:when test="$[jvar_value== searchBy]">  
  2.                       <option value="${jvar_value}" selected="selected">${jvar_value}</option>  
  3.             </j:when>  
  4.             <j:otherwise>  
  5.                       <option value="${jvar_value}">${jvar_value}</option>  
  6.             </j:otherwise>