...
Table of Contents | ||||
---|---|---|---|---|
|
...
Adding a Field to an Element Component
The topic Quick Start explains how to create a very basic element component using the element archetype. The archetype generates the following files (in the case of the HelloWorld example):
Resource | Description |
---|---|
Activator.java | Bundle activator |
CustomElement.java | Interface representing the custom element |
CustomElementController.java | Controller of the element component |
CustomElementFBO.java | Form backing object of the element component |
CustomElementImpl.java | Component and element implementation (business object) |
editCustomElement.jspf | JSP that renders the element in the Edit environment |
messages_en_US.properties | US English language file |
messages_nl_NL.properties | Dutch language file |
showCustomElement.xml | Descriptor of the JSP rendering the element on the Website environment |
showCustomElement.jspf | JSP rendering the element on the Website environment |
smallCustomElementIcon.gif | Small icon associated with the element |
largeCustomElementIcon.gif | Small Large icon associated with the element |
This part explains how to enhance this component with an additional field called "Author". To add this field to the Hello World element component, the following steps must be performed:
...
The Business object CustomElementImpl.java
represents the data model of the Hello World element. Since we want the author field to be persisted, we will add this property to this class. We define the property as an instance variable and add a getter and setter for it both in the interface and the implementation:
CustomElement.java
Code Block | ||
---|---|---|
| ||
/**
* Returns the author of the custom element.
* @return the author of the custom element
*/
String getAuthor();
/**
* Sets the author of the custom element.
* @param author the author of the custom element to set
*/
void setAuthor(String author);
|
CustomElementImpl.java
Code Block | ||
---|---|---|
| ||
@Property public String getAuthor() { return JcrUtil.getString(getNode(), "myJcrPrefix:author"); } public void setAuthor(String author) { JcrUtil.setString(getNode(),"myJcrPrefix:author", author); } |
...
Since the author must also be editable in the Editor, we also add the field to the Form backing object, CustomElementFBO.java
. This is done in a similar way as was done for the business object:
Code Block | ||
---|---|---|
| ||
private String myAuthor; public String getAuthor() { return myAuthor; } public void setAuthor(String author) { myAuthor= author; } |
...
To each of these language files the author label must be added. The ID of the label is suffixed by an ‘=’ and followed by the translated value in the language to be added. The following code snippet needs to be added to the messages_en_US.properties and must be repeated for each supported language:
Code Block | ||
---|---|---|
| ||
helloworldelement.author=Author |
...
Because "Author" must be editable by users logged in to the XperienCentral Workspace, we must add the field to the JSP that renders the element (editCustomElement.jspf
). Standard tags for property editing are supported by the wmedit
tag library. The wmedit
tag library generates the HTML for editing a property of a particular type. The property type that the tag should generate the HTML for is provided after the “:” separator. For a regular text input field the edit tag is input. To create an input field for editing the author, add this to the JSP:
Code Block | ||
---|---|---|
| ||
<fmt:message key="helloworldelement.author" />: <wmedit:input path="author"/> |
...
Libraries must be imported into the JSP, therefore the header of the JSP should contain at least the following lines:
Code Block | ||
---|---|---|
| ||
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="wmedit" uri="http://www.gx.nl/taglib/wmedit"%>
|
...
The "Author" field can now be edited in the Editor but must also be shown in the website environment. We therefore enhance the show JSP (showCustomElement.jspf
) to display its value:
Code Block | ||
---|---|---|
| ||
<c:set var="element" value="${presentationcontext.element}" /> Author: ${element.author} |
...
...
Adding a Field to a Panel Component
In Quick Start it is explained how to create a very basic panel component using the panel archetype. This panel consists of only one tab, the "HelloWorld" tab. The archetype generates the following files in case of the HelloWorld example:
Resource | Description |
---|---|
Activator.java | The bundle activator |
CustomPanelController.java | The controller of the whole panel |
CustomPanel.java | The form backing object of the whole panel |
CustomTabController.java | The controller of the HelloWorld tab contained by the panel |
CustomTabFBO.java | The form backing object of the HelloWorld tab contained by the panel |
customTab.jspf | The JSP that renders the HelloWorld tab |
messages_en_US.properties | The US English language file |
messages_nl_NL.properties | The Dutch language file |
...
This part explains how to enhance this component with an additional field named "Author". To add this field to the HelloWorld panel component, perform the following steps:
...
Since the author must be editable in the panel within the Editor, we also add the field to the form backing object (CustomTabFBO.java)
:
Code Block | ||
---|---|---|
| ||
private String myAuthor; public String getAuthor() { return myAuthor; } public void setAuthor(String author) { myAuthor = author; } |
...
See Adding a Language Label for a complete description of adding language labels. The following snippet should be added to each language file:
Code Block | ||
---|---|---|
| ||
helloworldpanel.author=Author |
...
When adding language labels, be sure that they conform to the development guidelines (G027 and G028 in particular).
The following snippet should be added to the customTab.jspf
(see Adding a Field to the Edit JSP for a complete description of adding a field to the edit JSP):
Code Block | ||
---|---|---|
| ||
<fmt:message key="helloworldpanel.author" />: <wmedit:input path="command.author" /> |
...
Adding a field to a Media Item component
In Quick Start it is explained how to create a very basic media item component using the media item archetype. The archetype generates the following files in case of the HelloWorld example:
Resource | Description |
---|---|
Activator.java | Bundle activator |
CustomMediaItemController.java | Controller of the metadata part of the custom media item |
CustomMediaItemVersion.java | Interface representing the custom media item version |
| Form backing object for the custom metadata part of the custom media item version |
| Implementation of the custom media item version |
| Descriptor of the JSP that renders the custom metadata part of the custom media item |
| JSP that renders the custom metadata part of the custom media item |
messages_en_US.properties | US English language file |
messages_nl_NL.properties | Dutch language file |
| Icon associated with the media item. Used in the menu and Media Repository search results. |
This part explains how to enhance this component with an additional metadata field named "Author". To add this field to the custom metadata part of the custom Media item component, perform the following steps:
- Add the property to the Media item version interface (
CustomMediaItemVersion.java
). - Add the property to the Media item version (
CustomMediaItemVersionImpl.java
). - Add the property to the form backing object (
CustomMediaItemVersionFBO.java
). - Add a label to the language files to translate “Author” in the supported languages.
- Add the field to the edit JSP (
editMetadata.jspf
).
...
Adding a
...
Property to the
...
Business Object
The Business object CustomMediaItemVersionImpl.java
"CustomMediaItemVersion
" represents the data model of the HelloWorld media item. Since we want the author metadata field to be persisted we add this property to this class. We define the property as instance variable and add a getter and setter for it:
CustomMediaItemVersion.java
Code Block | ||
---|---|---|
| ||
/**
* Returns the author of the custom media item.
* @return the author of the custom media item
*/
String getAuthor();
/**
* Sets the author of the custom media item.
* @param name the author of the custom media item to set
*/
void setAuthor(String author); |
CustomMediaItemVersionImpl.java
Code Block | ||
---|---|---|
| ||
@Property public String getAuthor() { return JcrUtil.getString(getPrivateNode(), "myJcrPrefixWCBConstants.NAMESPACE_PREFIX + ":author"); } public void setAuthor(String author) { JcrUtil.setString(getPrivateNode(),"myJcrPrefix WCBConstants.NAMESPACE_PREFIX + ":author", author); } |
Since the Author also must be editable in the Editor, we also add the metadata field to the Form backing object of the metadata part (CustomMediaItemVersionFBO.java
). This is done in a similar way as we did it for the business object:
Code Block | ||
---|---|---|
| ||
private String myAuthor; public String getAuthor() { return myAuthor; } public void setAuthor(String author) { myAuthor = author; } |
Adding a Field to the Edit JSP
See Adding a Field to the Edit JSP for a complete description of adding fields to the edit JSP. The following snippet should be added to the editMetadata.jspf
:
Code Block | ||
---|---|---|
| ||
<fmt:message key="helloworldmediaitem.author" />: <wmedit:input path="author"/> |
...
Language Label
The language label "helloworldmediaitem.author should" be present in both messages_en_US.properties
and messages_en_US.properties
files as e.g.:
...
Code Block | ||
---|---|---|
| ||
helloworldmediaitem.author=Auteur |
...
See Adding a Language Label for a complete description of adding language labels. The following snippet should be added to each language file:
When adding language labels, be sure that they conform to the Plugin Development Guidelines (G027 and G028 in particular).
...
Anchor | ||||
---|---|---|---|---|
|
When you add fields to a custom element, page metadata, custom content type and/or a panel that accept HTML or JavaScript and/or are rendered without any escaping mechanism, they should only be accessible to roles with at least the Administrator permission group assigned.
...