use of com.liferay.faces.alloy.component.inputdatetime.InputDateTime in project liferay-faces-alloy by liferay.
the class InputDateTimeRenderer method encodeMarkupEnd.
@Override
public void encodeMarkupEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
String clientId = uiComponent.getClientId(facesContext);
String inputClientId = clientId.concat(INPUT_SUFFIX);
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
InputDateTime inputDateTime = (InputDateTime) uiComponent;
InputDateTimeResponseWriter inputDateTimeResponseWriter = getInputDateTimeResponseWriter(responseWriter, inputClientId, isNative(browserSniffer, inputDateTime));
super.encodeMarkupEnd(facesContext, uiComponent, inputDateTimeResponseWriter);
// Determine whether or not the text input is enabled.
boolean disabled = inputDateTime.isDisabled();
// If the "showOn" attribute indicates that a button is to be rendered and the component is not being rendered
// for a mobile browser, then render the button.
String showOn = inputDateTime.getShowOn();
if (("both".equals(showOn) || "button".equals(showOn)) && !isNative(browserSniffer, inputDateTime)) {
ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
Application application = applicationFactory.getApplication();
// Create an icon component that is to remain detached from the component tree.
Icon icon = (Icon) application.createComponent(Icon.COMPONENT_TYPE);
String buttonIconName = getButtonIconName();
icon.setName(buttonIconName);
// Create a button component that that is also to remain detached from the component tree.
Button button = (Button) application.createComponent(Button.COMPONENT_TYPE);
List<UIComponent> buttonChildren = button.getChildren();
buttonChildren.add(icon);
button.setDisabled(disabled);
// If the component is enabled, then
if (!disabled) {
if ("button".equals(showOn)) {
String buttonClientId = getButtonClientId(facesContext, inputDateTime);
button.setId(buttonClientId);
} else {
// If the both the button and the input are supposed to trigger the datePicker, set the button's
// onclick to focus and click the input.
String onClick = BUTTON_ON_CLICK_EVENT.replace("{0}", inputClientId);
button.setOnclick(onClick);
}
}
// Invoke the button's renderer so that it renders itself and its child icon.
button.encodeAll(facesContext);
}
// If the component is enabled, then create the boundingBox and contentBox of the picker.
if (!disabled) {
responseWriter.startElement("div", uiComponent);
String boundingBoxClientId = clientId.concat(BOUNDING_BOX_SUFFIX);
responseWriter.writeAttribute("id", boundingBoxClientId, null);
responseWriter.startElement("div", uiComponent);
String contentBoxClientId = clientId.concat(CONTENT_BOX_SUFFIX);
responseWriter.writeAttribute("id", contentBoxClientId, null);
responseWriter.endElement("div");
responseWriter.endElement("div");
}
// Finish the encoding of the outermost </div> element.
responseWriter.endElement("div");
}
use of com.liferay.faces.alloy.component.inputdatetime.InputDateTime in project liferay-faces-alloy by liferay.
the class InputDateTimeRenderer method isSandboxed.
@Override
public boolean isSandboxed(FacesContext facesContext, UIComponent uiComponent) {
// In order to support the "lang" attribute of the YUI object, it is necessary to determine if the user has
// specified a locale other than that of the server or view root. If so, then the javascript must be rendered
// inline.
InputDateTime inputDateTime = (InputDateTime) uiComponent;
Locale locale = inputDateTime.getObjectAsLocale(inputDateTime.getLocale(facesContext));
UIViewRoot viewRoot = facesContext.getViewRoot();
Locale viewRootLocale = viewRoot.getLocale();
return !locale.equals(viewRootLocale);
}
use of com.liferay.faces.alloy.component.inputdatetime.InputDateTime in project liferay-faces-alloy by liferay.
the class InputDateTimeRenderer method getModules.
protected String[] getModules(String defaultModule, FacesContext facesContext, UIComponent uiComponent) {
String[] modules = new String[] { defaultModule };
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
InputDateTime inputDateTime = (InputDateTime) uiComponent;
if (isNative(browserSniffer, inputDateTime)) {
modules[0] = defaultModule.concat("-native");
} else {
Map<String, List<ClientBehavior>> clientBehaviorMap = inputDateTime.getClientBehaviors();
List<ClientBehavior> valueChangeClientBehaviors = clientBehaviorMap.get(VALUE_CHANGE);
if ((valueChangeClientBehaviors != null) && !valueChangeClientBehaviors.isEmpty()) {
modules = StringHelper.append(modules, NODE_EVENT_SIMULATE);
}
}
return modules;
}
use of com.liferay.faces.alloy.component.inputdatetime.InputDateTime in project liferay-faces-alloy by liferay.
the class InputDateTimeRenderer method encodeMarkupBegin.
@Override
public void encodeMarkupBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
// Start the encoding of the outermost <div> element.
ResponseWriter responseWriter = facesContext.getResponseWriter();
String clientId = uiComponent.getClientId(facesContext);
responseWriter.startElement("div", uiComponent);
// Encode the "id" attribute on the outermost <div> element.
responseWriter.writeAttribute("id", clientId, "id");
// Encode the "class" and "style" attributes on the outermost <div> element.
RendererUtil.encodeStyleable(responseWriter, (Styleable) uiComponent);
// Start the encoding of the text input by delegating to the renderer from the JSF runtime.
String inputClientId = clientId.concat(INPUT_SUFFIX);
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
InputDateTime inputDateTime = (InputDateTime) uiComponent;
InputDateTimeResponseWriter inputDateTimeResponseWriter = getInputDateTimeResponseWriter(responseWriter, inputClientId, isNative(browserSniffer, inputDateTime));
super.encodeMarkupBegin(facesContext, uiComponent, inputDateTimeResponseWriter);
}
use of com.liferay.faces.alloy.component.inputdatetime.InputDateTime in project liferay-faces-alloy by liferay.
the class InputDateTimeRenderer method getYUIConfig.
@Override
public String getYUIConfig(FacesContext facesContext, ResponseWriter responseWriter, UIComponent uiComponent) throws IOException {
InputDateTime inputDateTime = (InputDateTime) uiComponent;
Locale locale = inputDateTime.getObjectAsLocale(inputDateTime.getLocale(facesContext));
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("{lang:");
// RFC 1766 requires the subtags of locales to be delimited by hyphens rather than underscores.
// http://www.faqs.org/rfcs/rfc1766.html
stringBuilder.append("'");
String localeString = locale.toString().replaceAll("_", "-");
stringBuilder.append(localeString);
stringBuilder.append("'}");
return stringBuilder.toString();
}
Aggregations