Best Practice/JSF useful tipps etc

From MPDLMediaWiki
Jump to navigation Jump to search

Best practice tipps for JSF and related components[edit]

JSF general[edit]

HTML behavior[edit]

    • if you use HTML-Tags that immediately close after there opened (i.e. or ) it might be, that JSF reorders the closing tags to the end of the wrapping section for no good reason. So

<div> <span class="something"></span> <a href="some url">click</a> <span class="something"></span> </span><a href="some url">click</a> <span class="something"></span> </div>

might lead to

<div> <span class="something"> <a href="some url">click</a> <span class="something"> </span><a href="some url">click</a> <span class="something"></span></span> </div>

You can avoid that by using active jsf components like <h:panelGroup styleClass="something" /> or <h:outputText styleClass="something" /> instead.

Trinidad components[edit]

    • Trinidad iterator <tr:iterator>
      • you can use html components for output i.e. <h:outputText> --- MFranke 16:08, 9 December 2008 (UTC) The term "html components" IMO is confusing, I'd prefer "default JSF components".
      • you can use html components for text input i.e. <h:inputText> --- MFranke 16:05, 9 December 2008 (UTC) To me this seems not to be a good idea: Better use <tr:inputText/>.
      • you should avoid html components for triggering actions in the iterator like add / remove elements. If you notice strange behaviour when performing actions (i.e. ArrayOutOfBoundsExceptions) look for non-Trinidad components in the iterator first.
      • The first element in a trinidad iterator may not be a simple html element like
        . You will have to use "active" components instead like <h:panelgroup layout="block">. This will generate a
        element.
      • if you need the index of the current iterator row you can add the tag "varstatus". Example: <tr:iterator var="component" id="fileUploads" value="#{EasySubmission.files}" binding="#{EasySubmission.fileIterator}" varStatus="index">. Then you can get the current row index by querying like this: <h:outputText value="#{EasySubmission.fileIterator.rowIndex}" />. NOTE: you will have to create a binding with the related baccking bean in the iterator (binding="#{EasySubmission.fileIterator}"). For this you have to add the following to the backing bean: private UIXIterator fileIterator = new UIXIterator(); Don't forget to gererate getters and setters!!! This binding is necessary for the component in the jsp page to get a row index. Attention: if you want to nest objects binded to an iterator into other objects binded to an iterator, you might run into problems with mixed data in the iterators
      • Trinidad iterators have a default paging size which leads to the bahaviour that -by default - just 25 entries are shown. There is an attribute "rows" for iterator tag. If you set the value to "0" (zero), paging is turned off and all entries are shown.

PubMan specific[edit]

  • Breadcrumb
    • The breadcrumb navigation in PubMan detects every page the user navigates to automatically. To support this feature you have to add a key/value pair in the resource bundles for labels. The key has to be the same as the page name without the suffix ".jsp". Example: If you want to add the page "LocalTagsPage.jsp" you have to add the following key/value pair to the label resource bundle(s): LocalTagsPage = Local Tags. NOTE: Don't forget to add this pair for all supported languages!!!