Guidelines for portlet output
Prohibited Elements in portletsSiteVision is a portlet container and a portlet only renders output for a part of a web page. Therefore some elements are NOT allowed in the output (html/xhtml) of a portlet.
The following elements are prohibited:
Adhere to standardsYou should in your code always strive to follow XHTML and WCAG. Regardless of what context you write your output code (e.g. in a custom portlet, in a SiteVision HTML portlet, in a SiteVision Script portlet, in a SiteVision JCR menu portlet, or in a SiteVision Proxy portlet etc). More information and examples is available in the General output guidelines.
Use namespace to differ between instancesAlways make sure several instances of your portlet can be put on a page without loss of functionality or any validation errors/warnings.
A typical example is when your portlet has some inputs. Since inputs should have corresponding labels connected via an id, you should never hard-code the id of inputs. Below is an example of a portlet output that results in validation failures and possible interaction problems if several instances is put on the same page:
...<label for="thePhoneId">Phone: </label><input id="thePhoneId" type="text" name="phone" />...
To make sure you get an unique id, you can use the getPortletNamespace method of the PortletContextUtil class in the SiteVision Utility API. An example of how to get a unique id for your label is presented below:
import senselogic.sitevision.api.Utils;import senselogic.sitevision.api.context.PortletContextUtil; ...// retrieve an Utils instance from the SiteVision Utility API Utils utils = (Utils) portletRequest.getAttribute("sitevision.utils");
// get an unique id based on the namespace of the portlet
PortletContextUtil ctxUtil = utils.getPortletContextUtil();
String phoneId = ctxUtil.getPortletNamespace("phone");
The phoneId String in the example above will have a value something like "phone12_2b9561c511855e0ab91800015" when the actual code is executed. This can be used in your output code when the portlet is rendered.
If you use Velocity for rendering and you have put the "phoneId" String on the VelocityContext it could look like this:
...<label for="$phoneId">Phone: </label><input id="$phoneId" type="text" name="phone" /> ...