1

Lets say I have a field that can take 3 attributes

<myTag a="something" b="something" c="something" />

Let's say I want to only include those a,b,c attributes when a variables are not blank. So with EL it becomes something like this

<myTag a="${varA}" b="${varB}" c="${varC}" />

In the case that one or more of the variables are blank (say varB is empty) I'm getting output like:

<myTag a="a val" b c="c val" />

So b is still there, but passing a blank value. This can cause problems with some spring <form:etc> tags if an attribute is blank (say itemLabel on form:options for example) What if I don't want that? Is there an easy way to have the attribute not show up altogether?

I get that I can do

<c:if test="${empty b}">
    <myTag a="${varA}" c="${varC}" />
</c:if>

But that means we need a giant decision tree as the number of attributes increase if each one can possibly be blank.

Does anyone know a better way to do this?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Luke
  • 1,218
  • 1
  • 24
  • 40
  • 1
    This is not a JSTL tag. This is a custom JSP tag. To learn what exactly JSTL is, head to http://stackoverflow.com/tags/jstl/info I fixed the terminology in your question. – BalusC Mar 15 '16 at 08:12

0 Answers0