Poll Component Developer Guide - Rendering
Rendering the Poll
Available Poll Data
In order to be able to create rendering code (JSP or Freemarker), you have to know what data is available for rendering. The following table describes this.
Field | Description |
---|---|
pollDocument | Refers to the root-level HST bean, representing the processed poll document. For poll documents of the plugin-supplied type, the bean is implemented by org.onehippo.forge.poll.contentbean.PollDocument. If no poll document is available, this field is null and no further rendering should be attempted. While custom poll documents may provide extra properties, the plugin-supplied document type only exposes the poll field: |
pollDocument.poll | Refers to the HST bean representing the poll compound. This bean is implemented by org.onehippo.forge.poll.contentbean.compound.Poll. |
pollDocument.poll.text | String field containing the value of the text attribute of the poll compound. |
pollDocument.poll.introduction | String field containing the value of the introduction attribute of the poll compound. |
pollDocument.poll.options | List of HST beans specifying the options available for this poll document. Each option is implemented by org.onehippo.forge.poll.contentbean.compound.Option. |
pollDocument.poll.options[].value | String field containing the value of the value attribute of the selected option. |
pollDocument.poll.options[].label | String field containing the value of the label attribute of the selected option. |
voteSuccess | Boolean indicating, when a voting attempt was made, if the attempt was successful or not. If no voting attempt was made, the field is not available |
option | String containing the option previously voted on. May not be available. |
pollVotes | Refers to a Java bean of type org.onehippo.forge.poll.bean.PollVotesBean which contains the votes data pertaining to the pollDocument. Just like the poll compound, this bean provides votes data as options: |
pollVotes.options | List of beans representing the options available for the poll document |
pollVotes.options[].value | Same as pollDocument.poll.options[].value |
pollVotes.options[].label | Same as pollDocument.poll.options[].label |
pollVotes.options[].votesCount | Long integer indicating the number of votes cast onto this option. |
pollVotes.options[].votesPercentage | Long integer indicating the (rounded-off) percentage of this option relative to all votes for this document. |
Creating a Template
Your poll is rendered using a JSP or Freemarker template. The poll plugin comes with a Freemarker template illustrating the rendering of the attributes of the poll component. You can find the code in the repository under hst:[your_project]/hst:configurations/hst:default/hst:templates/poll.component.ftl@hst:script.
If necessary, customize this code and make sure it is part of your site.war.
If you use your customized code, refer to it by configuring a new template under /hst:[your_project]/hst:configurations/[your_project]/hst:templates, pointing the component's hst:renderpath attribute to your template.
If you use the default Freemarker template provided by the poll plug-in, a template called poll.component.ftl is available to be used by your component.