use of com.liferay.faces.util.component.ClientComponent in project liferay-faces-alloy by liferay.
the class AlloyRendererCommon method encodeJavaScriptBegin.
/* package-private */
static void encodeJavaScriptBegin(FacesContext facesContext, UIComponent uiComponent, AlloyRenderer alloyRenderer, String[] modules, boolean sandboxed) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
if (sandboxed) {
String yuiConfig = alloyRenderer.getYUIConfig(facesContext, responseWriter, uiComponent);
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
String alloyBeginScript = AlloyRendererUtil.getAlloyBeginScript(modules, yuiConfig, browserSniffer);
responseWriter.write(alloyBeginScript);
}
if (facesContext.getPartialViewContext().isAjaxRequest() && (uiComponent instanceof ClientComponent)) {
ClientComponent clientComponent = (ClientComponent) uiComponent;
String clientVarName = alloyRenderer.getClientVarName(facesContext, clientComponent);
String clientKey = clientComponent.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
responseWriter.write("if(");
responseWriter.write(clientVarName);
responseWriter.write("){");
responseWriter.write(clientVarName);
responseWriter.write(".destroy();}");
}
}
use of com.liferay.faces.util.component.ClientComponent in project liferay-faces-alloy by liferay.
the class PopoverRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
Popover popover = (Popover) uiComponent;
ClientComponent clientComponent = (ClientComponent) uiComponent;
String clientVarName = getClientVarName(facesContext, clientComponent);
String clientKey = clientComponent.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
if (popover.isHideIconRendered()) {
// Add an "x" toolbar icon so that the popover can be hidden just like alloy:dialog can.
responseWriter.write("Liferay.component('");
responseWriter.write(clientKey);
responseWriter.write("').addToolbar([{cssClass:'close',label:'\u00D7',on:{click:function(event){Liferay.component('");
responseWriter.write(clientKey);
responseWriter.write("').hide();}},render:true}],'header');");
}
// Move the overlayBody div into the popover-content div.
String clientId = popover.getClientId(facesContext);
String overlayBodyClientId = clientId.concat(OVERLAY_BODY_SUFFIX);
String escapedOverlayBodyClientId = ComponentUtil.escapeClientId(overlayBodyClientId);
String contentBoxClientId = clientId.concat(CONTENT_BOX_SUFFIX);
String escapedContentBoxClientId = ComponentUtil.escapeClientId(contentBoxClientId);
responseWriter.write("A.one('#");
responseWriter.write(escapedOverlayBodyClientId);
responseWriter.write("').appendTo(A.one('div#");
responseWriter.write(escapedContentBoxClientId);
responseWriter.write(">div.popover-content'));");
if (popover.isDismissible()) {
encodeOverlayDismissible(responseWriter, popover, clientKey);
}
encodeOverlayJavaScriptCustom(responseWriter, facesContext, popover, clientKey);
if ((popover.getFor() == null) && facesContext.isProjectStage(ProjectStage.Development)) {
logger.error("The 'for' attribute is required for alloy:popover");
}
}
use of com.liferay.faces.util.component.ClientComponent in project liferay-faces-alloy by liferay.
the class AutoCompleteRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
// If the developer has specified a server-side filtering, then
if (isServerFilteringEnabled(uiComponent)) {
ResponseWriter responseWriter = facesContext.getResponseWriter();
ClientComponent clientComponent = (ClientComponent) uiComponent;
String clientVarName = getClientVarName(facesContext, clientComponent);
String clientKey = clientComponent.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
// J-
// var clientVarName = Liferay.component('clientKey');
// J+
encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
JavaScriptFragment clientVarNameJSFragment = new JavaScriptFragment(clientVarName);
String clientId = uiComponent.getClientId(facesContext);
String hiddenClientId = clientId + HIDDEN_SUFFIX;
String namingContainerId = null;
UIViewRoot viewRoot = facesContext.getViewRoot();
if (viewRoot instanceof NamingContainer) {
namingContainerId = viewRoot.getContainerClientId(facesContext);
}
// J-
// LFAI.setAutoCompleteEventListeners(A, clientVarName, 'escapedHiddenClientId', 'clientId',
// 'namingContainerId');
// J+
encodeFunctionCall(responseWriter, "LFAI.initAutoCompleteServerMode", clientVarNameJSFragment, hiddenClientId, clientId, namingContainerId);
}
}
use of com.liferay.faces.util.component.ClientComponent in project liferay-faces-alloy by liferay.
the class AutoCompleteRenderer method encodeJavaScript.
/**
* This method is being overridden in order to allow server-side filtering of autoComplete items when server-side
* filtering is enabled during an Ajax request and there is a query. Otherwise, this method simply calls
* super.encodeJavaScript() in order to render the component normally.
*/
@Override
public void encodeJavaScript(FacesContext facesContext, UIComponent uiComponent) throws IOException {
AutoComplete autoComplete = (AutoComplete) uiComponent;
// If the developer has specified a server-side filtering during Ajax, then
if (isServerFilteringEnabled(autoComplete) && facesContext.getPartialViewContext().isAjaxRequest()) {
// If the user has specified a query, then
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
String clientId = uiComponent.getClientId(facesContext);
String hiddenClientId = clientId + HIDDEN_SUFFIX;
String query = requestParameterMap.get(hiddenClientId);
if ((query != null) && (query.length() > 0)) {
// Get the entire list of completion items.
List<String> items = autoComplete.getAllItems(facesContext);
// If the developer has specified a serverCustomFilter, then call their custom filtering method.
MethodExpression serverCustomFilter = autoComplete.getServerCustomFilter();
if (serverCustomFilter != null) {
items = invokeServerCustomFilter(facesContext.getELContext(), serverCustomFilter, query, items);
} else // Otherwise, if the developer has specified a serverFilterType, then call the corresponding filtering
// method.
{
String serverFilterType = autoComplete.getServerFilterType();
if (serverFilterType != null) {
Locale locale = facesContext.getViewRoot().getLocale();
AutoCompleteFilterFactory autoCompleteFilterFactory = new AutoCompleteFilterFactoryImpl();
AutoCompleteFilter autoCompleteFilter = autoCompleteFilterFactory.getAutoCompleteFilter(serverFilterType);
if (autoCompleteFilter != null) {
boolean caseSensitive = serverFilterType.contains("Case");
items = autoCompleteFilter.doFilter(query, items, caseSensitive, locale);
} else {
throw new IOException(serverFilterType + " is not a valid serverFilterType.");
}
}
}
// Build up a fragment of JavaScript that gets the client-side component.
ClientComponent clientComponent = (ClientComponent) uiComponent;
String clientVarName = getClientVarName(facesContext, clientComponent);
String clientKey = clientComponent.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
// J-
// Liferay.component('clientKey')
// J+
JavaScriptFragment liferayComponentJavaScriptFragment = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
// Build up a fragment of JavaScript that contains an array of the results.
// J-
// ['item1', 'item2', 'item3', ... 'itemN']
// J+
JavaScriptFragment[] results = AlloyRendererUtil.toEscapedJavaScriptStringArray(items);
// Buffer all JavaScript so that it is rendered in the <eval> section of the partial response.
BufferedScriptResponseWriter bufferedScriptResponseWriter = new BufferedScriptResponseWriter();
// J-
// LFAI.recieveAutoCompleteResults(Liferay.component('clientKey'), ['item1', 'item2', 'item3'],
// 'hiddenClientId')
// J+
encodeFunctionCall(bufferedScriptResponseWriter, "LFAI.setAutoCompleteServerResults", liferayComponentJavaScriptFragment, results, hiddenClientId);
String[] modules = getModules(facesContext, uiComponent);
renderScript(facesContext, bufferedScriptResponseWriter.toString(), modules, Script.ModulesType.ALLOY);
} else {
super.encodeJavaScript(facesContext, uiComponent);
}
} else {
super.encodeJavaScript(facesContext, uiComponent);
}
}
Aggregations