Search code examples
javahtmljspjstldisplaytag

custom html inside <display:column></display:cloumn>


I was wondering if its possible to render custom html inside of column tag, that is part of display table tag.

for example, i want my colum to have some dropdown list inside?

Using plain html that would be like:

<table>
...
<tr>
<td>
<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select> 
</td>
</tr>
</table>

is it possible to embed that select tag in display column? This is the demo of display column

<display:column property="${displayElem.name}" escapeXml="true" sortable="true" titleKey="errorHandler.${displayElem.name}" style="width: ${displayElem.length}" />

EDIT: When i try to remove property inside display column i get only html source code inside my table cell and not the html element rendering of that code.

 <display:column escapeXml="true"
       sortable="true" titleKey="errorHandler.${displayElem.name}"
       style="width: ${displayElem.length}" >
     <select>
       <option value="volvo">Volvo</option>
       <option value="saab">Saab</option>
       <option value="mercedes">Mercedes</option>
       <option value="audi">Audi</option>
     </select> 
</display:column>

SOLUTION: removing escapeXml="true" attribute solved problem

<display:column 
       sortable="true" titleKey="errorHandler.${displayElem.name}"
       style="width: ${displayElem.length}" >
     <select>
       <option value="volvo">Volvo</option>
       <option value="saab">Saab</option>
       <option value="mercedes">Mercedes</option>
       <option value="audi">Audi</option>
     </select> 
</display:column>

SOLUTION 2 for ultimate control

create class, extend it with decorator class and use it the display table tags

public class YourDecorationClass extends TableDecorator {

    public String getAction() {
        String code = "";

        code = "<select>" +
                "<option value='volvo'>Volvo</option>" +
                "<option value='volvo'>Saab</option>" +
                "<option value='volvo_RETRY'>Mercedes_RETRY</option>" +
                "<option value='audi'>Audi</option>";

        return code;
    }
}

and use decorator parameter in the display table tag

decorator="com.yourpackage.util.table.YourDecorationClass"

and of course remove escapeXml="true" from display column tag.


Solution

  • Yes, of course it's possible. The documentation of the tag says:

    Displays a property of a row object inside a table. MUST be nested inside of a Table tag. The value displayed will be the results of a decorator (if any); else the property named by the 'property' attribute; or if the 'property' attribute is null, then the results of evaluating the JSP body of the tag.

    (emphasis mine)