use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class InputDate method getPattern.
@Override
public String getPattern() {
String datePattern;
FacesContext facesContext = FacesContext.getCurrentInstance();
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
if (browserSniffer.isMobile() && isNativeWhenMobile()) {
datePattern = DEFAULT_HTML5_DATE_PATTERN;
} else {
datePattern = super.getPattern();
if (datePattern == null) {
// Provide a default datePattern based on the locale.
Object locale = getLocale();
datePattern = getDefaultDatePattern(locale);
}
}
return datePattern;
}
use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class ScriptsEncoderAlloyImpl method encodeScripts.
private void encodeScripts(FacesContext facesContext, ResponseWriter responseWriter, List<Script> scripts) throws IOException {
Set<String> sortedModules = new TreeSet<String>();
List<Script> alloyScripts = new ArrayList<Script>();
List<Script> basicScripts = new ArrayList<Script>();
for (Script script : scripts) {
Script.ModulesType modulesType = script.getModulesType();
if (Script.ModulesType.ALLOY.equals(modulesType)) {
String[] modules = script.getModules();
if (modules != null) {
for (String module : modules) {
sortedModules.add(module.trim());
}
}
alloyScripts.add(script);
} else {
basicScripts.add(script);
}
}
for (Script script : basicScripts) {
responseWriter.write(script.getSourceCode());
}
if (!alloyScripts.isEmpty()) {
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
String alloyBeginScript = AlloyRendererUtil.getAlloyBeginScript(sortedModules, null, browserSniffer);
responseWriter.write(alloyBeginScript);
for (Script alloyScript : alloyScripts) {
responseWriter.write("(function(){");
responseWriter.write(alloyScript.getSourceCode());
responseWriter.write("})();");
}
responseWriter.write("});");
}
}
use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class OutputScriptRenderer method encodeChildren.
@Override
public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException {
OutputScript outputScript = (OutputScript) uiComponent;
String name = outputScript.getName();
// render a JSF resource.
if ((name != null) && (name.length() > 0)) {
super.encodeChildren(facesContext, uiComponent);
} else // Otherwise, since it is not a JSF resource:
{
// If target="body" and this is not an Ajax request, then
String use = outputScript.getUse();
String target = outputScript.getTarget();
if ("body".equals(target) && !facesContext.getPartialViewContext().isAjaxRequest()) {
ResponseWriter responseWriter = facesContext.getResponseWriter();
BufferedScriptResponseWriter bufferedScriptResponseWriter = new BufferedScriptResponseWriter();
facesContext.setResponseWriter(bufferedScriptResponseWriter);
super.encodeChildren(facesContext, uiComponent);
facesContext.setResponseWriter(responseWriter);
Script script;
String bufferedScriptString = bufferedScriptResponseWriter.toString();
ExternalContext externalContext = facesContext.getExternalContext();
if ((use != null) && (use.length() > 0)) {
String[] modules = use.split(",");
script = ScriptFactory.getScriptInstance(externalContext, bufferedScriptString, modules, Script.ModulesType.ALLOY);
} else {
script = ScriptFactory.getScriptInstance(externalContext, bufferedScriptString);
}
// Render the script at the bottom of the page immediately before the closing </body> tag.
FacesRequestContext facesRequestContext = FacesRequestContext.getCurrentInstance();
facesRequestContext.addScript(script);
} else // correct modules around the script.
if ((use != null) && (use.length() > 0)) {
// Delegate to the JSF runtime Renderer, but replace the JSF runtime ResponseWriter with an
// OutputScriptResponseWriter which will render the YUI sandbox code around the script.
ResponseWriter responseWriter = facesContext.getResponseWriter();
// In order to determine the exact YUI sandbox string to write, the modules and browser information
// must be passed to RendererUtil.getAlloyBeginScript().
String[] modules = use.split(",");
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
String alloyBeginScript = AlloyRendererUtil.getAlloyBeginScript(modules, null, browserSniffer);
OutputScriptResponseWriter outputScriptResponseWriter = new OutputScriptResponseWriter(responseWriter, alloyBeginScript);
super.encodeChildren(facesContext, uiComponent, outputScriptResponseWriter);
} else // Otherwise, simply delegate to the JSF runtime renderer since target="head" or target="form".
{
super.encodeChildren(facesContext, uiComponent);
}
}
}
use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class InputDateRenderer method getAlloyClassName.
@Override
public String getAlloyClassName(FacesContext facesContext, UIComponent uiComponent) {
String alloyClassName = super.getAlloyClassName(facesContext, uiComponent);
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
InputDate inputDate = (InputDate) uiComponent;
if (isNative(browserSniffer, inputDate)) {
alloyClassName = alloyClassName.concat("Native");
}
return alloyClassName;
}
use of com.liferay.faces.util.client.BrowserSniffer 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");
}
Aggregations