HTML and CSS Reference
In-Depth Information
* Utility method that evaluates if the value in the given attribute is
* {@link Boolean.TRUE}.
* @param attributeName Name of the attribute to evaluate
* @return {@code true} if the value of the attribute evaluates to
* {@link Boolean.TRUE}, otherwise {@code false} is returned
private boolean isAttributeTrue(String attributeName) {
boolean isBoolean = getAttribute(attributeName) instanceof java.lang.Boolean;
boolean isTrue = ((boolean) getAttribute(attributeName)) == Boolean.TRUE;
return isBoolean && isTrue;
The benefit of this method is that you can easily unit test the logic behind the component. You can also reuse
the composite component root for multiple components. For example, we have used the preceding class for both the
audio and video components. The disadvantage is that it will probably be extra work, in terms of lines of code, for
simple components. Also, it may not be obvious what exactly is being outputted from the composite component as the
output is now being generated and manipulated from both the Facelets view and the composite component root.
Supporting Sources and Tracks
Along with the video and audio elements, HTML 5 introduces the source and track elements that can be embedded
inside the video and audio elements to support multiple media formats and to provide text tracks. We have already
included sources and tracks to the available attributes in the interface of the composite component. In these attributes
we will expect a collection of objects since there would most likely be more than one source and track per video and
audio. The objects in the collection must expose the required properties to render the source and track elements,
so we have created two data transfer objects to keep details about the source, as shown in Listing 8-9, and about the
track, as shown in Listing 8-10.
Listing 8-9. Is a Simple Data Transfer Object for Keeping Information About a Media Source
import java.util.Objects;
* {@linkplain MediaSource Media source} used to provide the
* {@link UIMediaComponent} with alternative media files.
public class MediaSource {
private String source;
private String type;
* Creates a new instance of {@link MediaSource} with a blank source and
* mime type.
Search WWH ::

Custom Search