HTML and CSS Reference
In-Depth Information
Listing 8-8. UIMediaComponent.java Representing the Composite Component Root Specified as the
componentType in Listing 8-3
package com.apress.projsf2html5.components.media;
import java.io.IOException;
import javax.el.ValueExpression;
import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponent;
import javax.faces.component.UINamingContainer;
import javax.faces.context.FacesContext;
/**
* Composite component for the {@code <audio/>} and {@code <video/>} elements.
*/
@FacesComponent("UIMediaComponent")
public class UIMediaComponent extends UINamingContainer {
private static final String ELEMENT_ID = "media-player";
private static final String ATTRIBUTE_AUTOPLAY = "autoplay";
private static final String ATTRIBUTE_LOOP = "loop";
private static final String ATTRIBUTE_MUTED = "muted";
private static final String ATTRIBUTE_CONTROLS = "controls";
private static final String ATTRIBUTE_POSTER = "poster";
private static final String ATTRIBUTE_WIDTH = "width";
private static final String ATTRIBUTE_HEIGHT = "height";
public String getElementId() {
return ELEMENT_ID;
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
super.encodeBegin(context);
UIComponent element = findMediaElement();
addAttributeIfTrue(element, ATTRIBUTE_AUTOPLAY);
addAttributeIfTrue(element, ATTRIBUTE_LOOP);
addAttributeIfTrue(element, ATTRIBUTE_MUTED);
addAttributeIfTrue(element, ATTRIBUTE_CONTROLS);
addAttributeIfNotNull(element, ATTRIBUTE_POSTER);
addAttributeIfNotNull(element, ATTRIBUTE_WIDTH);
addAttributeIfNotNull(element, ATTRIBUTE_HEIGHT);
}
private void addAttributeIfNotNull(UIComponent component, String attributeName) {
Object attributeValue = getAttribute(attributeName);
if (attributeValue != null) {
component.getPassThroughAttributes().put(attributeName, attributeValue);
}
}
Search WWH ::




Custom Search