-1

I have a jsp that uses JSTL to manage the value of the beans and I need to align two elements without touching the rest of the page (that was not written by me)

I have two rows like this:

 AAAAAAAAAAAAAAAA  element one
 element two

IF "AAAAAAAAAAAAAAAA" (a variable) has a value I want to align "element two" with "element one" (that has AAA before, so is more at right than the second one)

So I want to obtain this (only if AAAA.. has a value):

 AAAAAAAAAAAAAAAA  element one
                   element two

the part is:

<c:out value='${variableA}'/> <c:out value='${elementOne}'/>

<c:if test="${variableA != ''}">
     --I need to insert spaces here--
</c:if>
<c:out value='${elementTwo}'/>

I tried inserting many &nbsp, but they get inserted even when the "if" is false. I tried with div and p but without success and I tried valorizing a JSTL variable with many "&nbsp" but obviously they get trimmed when converted into html. Can someone help me putting some spaces over there? :( Thank you very much :)

Pipkin
  • 99
  • 1
  • 2
  • 7

3 Answers3

4

use ${" "} to have real space, not &nbsp;

Are Butuv
  • 292
  • 3
  • 10
1

You need to change the <c:if> empty condition like below

<c:out value='${variableA}'/> <c:out value='${elementOne}'/> <br>

<c:if test="${not empty variableA}">
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</c:if>
<c:out value='${elementTwo}'/>

To keep alignment better to use table tag instead of adding spaces

    <table>
        <tr>
            <td> <c:out value='${variableA}'/> </td> 
            <td> <c:out value='${elementOne}'/> </td>
        </tr>

        <tr>
            <td> <c:out value='${variableB}'/> </td> 
            <td> <c:out value='${elementTwo}'/> </td>
        </tr>

     </table>
vjy
  • 1,184
  • 1
  • 10
  • 24
  • 1
    I need more reputation to upvote you (I will do it when I will able to :) ). Thank you so much! I totally ignored the "not empty" part and so I thought the problems were others. Now it's working. Thank you even for the table tip part, have a nice day :) – Pipkin Jun 11 '14 at 06:47
  • @Pipkin No probelm, glad to help :) – vjy Jun 11 '14 at 07:16
0
   <style>
        .left-div{
            float: left;
            width: 200px;
            display: block;
        }
        .main-div{
            width: 400px;
        }

    </style>


  <div class="main-div">
        <div class="left-div">AAAAAAAAAAA</div><div class="left-div">EL 1</div>

        <div class="left-div"> &nbsp; </div><div class="left-div">EL 2</div>            
  </div>
Tusar
  • 759
  • 5
  • 21