Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

As discussed in CSS Best Practices and JavaScript Best Practices portlets require that all HTML element ids be namespaced to prevent duplicate ids on a page when a portlet is included multiple times on a page.  Some JSP tag libraries automatically generate ids if they are not specified, so a developer should specify the ids.  For example

<!-- Spring form tag will cause duplicate ids -->
<form:select path="title" items="${titles}" />

<!-- when rendered might look something like this -->
<select id="title" name="title">
  <option value="Mr">Mr</option>
  <option value="Mrs">Mrs</option>
  <option value="Miss">Miss</option>
</select>

<!-- Instead specify a namespaced id -->

<c:set var="n"><portlet:namespace /></c:set>

<form:select id="${n}title" path="title" items="${titles}" />
  • No labels