use of javax.faces.component.behavior.ClientBehaviorContext in project liferay-faces-alloy by liferay.
the class DataTableRenderer method getColumnClientBehaviorScript.
protected String getColumnClientBehaviorScript(FacesContext facesContext, DataTable dataTable, Column column, String clientId) {
String clientBehaviorScript = null;
Map<String, List<ClientBehavior>> clientBehaviorMap = column.getClientBehaviors();
String defaultEventName = column.getDefaultEventName();
List<ClientBehavior> clientBehaviorsForEvent = clientBehaviorMap.get(defaultEventName);
if (clientBehaviorsForEvent != null) {
for (ClientBehavior clientBehavior : clientBehaviorsForEvent) {
List<ClientBehaviorContext.Parameter> parameters = new ArrayList<ClientBehaviorContext.Parameter>();
String sortColumnClientIdParamName = clientId.concat("_sortColumnClientId");
String sortColumnClientId = column.getClientId(facesContext);
parameters.add(new ClientBehaviorContext.Parameter(sortColumnClientIdParamName, sortColumnClientId));
String eventMetaKeyParamName = clientId.concat("_eventMetaKey");
parameters.add(new ClientBehaviorContext.Parameter(eventMetaKeyParamName, "event.metaKey"));
ClientBehaviorContext clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, dataTable, defaultEventName, clientId, parameters);
clientBehaviorScript = clientBehavior.getScript(clientBehaviorContext);
}
}
if (clientBehaviorScript != null) {
clientBehaviorScript = clientBehaviorScript.replaceFirst("'event.metaKey'", "event.metaKey");
}
return clientBehaviorScript;
}
use of javax.faces.component.behavior.ClientBehaviorContext in project liferay-faces-alloy by liferay.
the class AccordionRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
// Encode a script that will handle the client-side state of the selected tab index, as well as submitting
// Ajax requests to support server-side events.
Accordion accordion = (Accordion) uiComponent;
// var accordionClientVarName = Liferay.component('{clientKey}');
String clientVarName = getClientVarName(facesContext, accordion);
String clientKey = accordion.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
ResponseWriter responseWriter = facesContext.getResponseWriter();
encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
// Expand the selected tab.
Integer selectedIndex = accordion.getSelectedIndex();
if ((selectedIndex != null) && (selectedIndex > -1)) {
DataEncoderBase dataEncoder = new DataEncoderTabJavaScriptImpl(selectedIndex, clientVarName);
dataEncoder.encodeColumns(facesContext, accordion);
}
// LFAI.initAccordion(multiple, accordionClientVarName, '{clientId}selectedIndex', '{clientId}',
// [tabExpandClientBehaviorScriptFunction1, tabExpandClientBehaviorScriptFunction2,
// tabExpandClientBehaviorScriptFunction3], '{clientId}collapsedTabIndex',
// [tabCollapseClientBehaviorScriptFunction1, tabCollapseClientBehaviorScriptFunction2,
// tabCollapseClientBehaviorScriptFunction3]);
boolean multiple = accordion.isMultiple();
String clientId = accordion.getClientId(facesContext);
StringBuilder tabExpandedClientBehaviors = new StringBuilder();
tabExpandedClientBehaviors.append("[");
StringBuilder tabCollapsedClientBehaviors = new StringBuilder();
tabCollapsedClientBehaviors.append("[");
boolean firstTabExpandedClientBehavior = true;
boolean firstTabCollapsedClientBehavior = true;
Map<String, List<ClientBehavior>> clientBehaviorMap = accordion.getClientBehaviors();
Collection<String> eventNames = accordion.getEventNames();
for (String eventName : eventNames) {
List<ClientBehavior> clientBehaviorsForEvent = clientBehaviorMap.get(eventName);
if (clientBehaviorsForEvent != null) {
for (ClientBehavior clientBehavior : clientBehaviorsForEvent) {
ClientBehaviorContext clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, accordion, eventName, clientId, null);
// an Ajax request.
if (TabExpandEvent.TAB_EXPAND.equals(eventName)) {
if (!firstTabExpandedClientBehavior) {
tabExpandedClientBehaviors.append(",");
}
// J-
// function(event) {
// jsf.ajax.request(this, event, {'javax.faces.behavior.event': 'tabSelect'})
// };
// J+
tabExpandedClientBehaviors.append("function(event){");
tabExpandedClientBehaviors.append(clientBehavior.getScript(clientBehaviorContext));
tabExpandedClientBehaviors.append("}");
firstTabExpandedClientBehavior = false;
} else // an Ajax request.
if (TabCollapseEvent.TAB_COLLAPSE.equals(eventName)) {
if (!firstTabCollapsedClientBehavior) {
tabCollapsedClientBehaviors.append(",");
}
// J-
// function(event) {
// jsf.ajax.request(this, event, {'javax.faces.behavior.event': 'tabSelect'})
// };
// J+
tabCollapsedClientBehaviors.append("function(event){");
tabCollapsedClientBehaviors.append(clientBehavior.getScript(clientBehaviorContext));
tabCollapsedClientBehaviors.append("}");
firstTabCollapsedClientBehavior = false;
}
}
}
}
tabExpandedClientBehaviors.append("]");
tabCollapsedClientBehaviors.append("]");
encodeFunctionCall(responseWriter, "LFAI.initAccordion", multiple, new JavaScriptFragment(clientVarName), clientId + "selectedIndex", clientId, new JavaScriptFragment(tabExpandedClientBehaviors.toString()), clientId + "collapsedTabIndex", new JavaScriptFragment(tabCollapsedClientBehaviors.toString()));
}
use of javax.faces.component.behavior.ClientBehaviorContext in project liferay-faces-alloy by liferay.
the class ProgressBarRenderer method encodeHiddenAttributes.
@Override
protected void encodeHiddenAttributes(FacesContext facesContext, ResponseWriter responseWriter, ProgressBar progressBar, boolean first) throws IOException {
// render: true
encodeWidgetRender(responseWriter, first);
first = false;
// contentBox
String clientId = progressBar.getClientId(facesContext);
String contentBoxClientId = clientId.concat(CONTENT_BOX_SUFFIX);
encodeClientId(responseWriter, CONTENT_BOX, contentBoxClientId, first);
// Begin encoding event listeners that occur on the event.
encodeNonEscapedObject(responseWriter, "on", "", first);
responseWriter.write("{");
// complete
boolean onFirst = true;
String oncomplete = progressBar.getOncomplete();
Map<String, List<ClientBehavior>> clientBehaviorMap = progressBar.getClientBehaviors();
List<ClientBehavior> clientBehaviorsForComplete = clientBehaviorMap.get("progressComplete");
if ((oncomplete != null) || ((clientBehaviorsForComplete != null) && !clientBehaviorsForComplete.isEmpty())) {
// J-
// function(event) {
// oncomplete();
// jsf.ajax.request(...);
// jsf.ajax.request(...);
// ...
// jsf.ajax.request(...);
// }
// J+
StringBuilder onCompleteBuilder = new StringBuilder();
onCompleteBuilder.append("function(event){");
if (oncomplete != null) {
onCompleteBuilder.append(oncomplete);
}
if ((clientBehaviorsForComplete != null) && !clientBehaviorsForComplete.isEmpty()) {
ClientBehaviorContext clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, progressBar, "progressComplete", clientId, null);
for (ClientBehavior clientBehaviorForComplete : clientBehaviorsForComplete) {
onCompleteBuilder.append(clientBehaviorForComplete.getScript(clientBehaviorContext));
onCompleteBuilder.append(";");
}
}
onCompleteBuilder.append("}");
encodeNonEscapedObject(responseWriter, COMPLETE, onCompleteBuilder.toString(), onFirst);
onFirst = false;
}
// label
String label = progressBar.getLabel();
// J+
if ((label != null) && label.contains(TOKEN)) {
String escapedLabel = RendererUtil.escapeJavaScript(label);
encodeNonEscapedObject(responseWriter, VALUE_CHANGE, "function(event){this.set('label','".concat(escapedLabel).concat("'.replace(LFAI.TOKEN_REGEX, event.newVal));}"), onFirst);
onFirst = false;
}
// Finish encoding event listeners that occur on the event.
responseWriter.write("}");
}
use of javax.faces.component.behavior.ClientBehaviorContext in project liferay-faces-alloy by liferay.
the class PaginatorRenderer method getClientBehaviorScript.
protected String getClientBehaviorScript(FacesContext facesContext, Paginator paginator, String clientId, String paginatorAction) {
String clientBehaviorScript = null;
Map<String, List<ClientBehavior>> clientBehaviorMap = paginator.getClientBehaviors();
String defaultEventName = paginator.getDefaultEventName();
String paginatorActionParamName = clientId.concat("_paginatorAction");
List<ClientBehavior> clientBehaviorsForEvent = clientBehaviorMap.get(defaultEventName);
if (clientBehaviorsForEvent != null) {
for (ClientBehavior clientBehavior : clientBehaviorsForEvent) {
List<ClientBehaviorContext.Parameter> parameters = new ArrayList<ClientBehaviorContext.Parameter>();
parameters.add(new ClientBehaviorContext.Parameter(paginatorActionParamName, paginatorAction));
ClientBehaviorContext clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, paginator, defaultEventName, clientId, parameters);
clientBehaviorScript = clientBehavior.getScript(clientBehaviorContext);
}
}
return clientBehaviorScript;
}
use of javax.faces.component.behavior.ClientBehaviorContext in project ART-TIME by Artezio.
the class SheetRenderer method encodeBehaviors.
/**
* Encode client behaviors to widget config
* <P>
* @param context
* @param sheet
* @param wb
* @throws IOException
*/
private void encodeBehaviors(FacesContext context, Sheet sheet, WidgetBuilder wb) throws IOException {
// note we write out the onchange event here so we have the selected
// cell too
Map<String, List<ClientBehavior>> behaviors = sheet.getClientBehaviors();
wb.append(",behaviors:{");
String clientId = sheet.getClientId();
// sort event (manual since callBack prepends leading comma)
wb.append("sort").append(":").append("function(s, event)").append("{").append("PrimeFaces.ab({source: '").append(clientId).append("',event: 'sort', process: '").append(clientId).append("', update: '").append(clientId).append("'}, arguments[1]);}");
// filter
wb.callback("filter", "function(s, event)", "PrimeFaces.ab({source: '" + clientId + "', event: 'filter', process: '" + clientId + "', update: '" + clientId + "'}, arguments[1]);");
if (behaviors.containsKey("change")) {
ClientBehaviorContext behaviorContext = ClientBehaviorContext.createClientBehaviorContext(context, sheet, "change", sheet.getClientId(context), null);
wb.callback("change", "function(source, event)", behaviors.get("change").get(0).getScript(behaviorContext));
}
if (behaviors.containsKey("cellSelect")) {
ClientBehaviorContext behaviorContext = ClientBehaviorContext.createClientBehaviorContext(context, sheet, "cellSelect", sheet.getClientId(context), null);
wb.callback("cellSelect", "function(source, event)", behaviors.get("cellSelect").get(0).getScript(behaviorContext));
}
wb.append("}");
}
Aggregations