use of com.liferay.faces.alloy.component.progressbar.ProgressBar in project liferay-faces-alloy by liferay.
the class ProgressBarRendererBase method encodeAlloyAttributes.
@Override
public void encodeAlloyAttributes(FacesContext facesContext, ResponseWriter responseWriter, UIComponent uiComponent) throws IOException {
ProgressBar progressBar = (ProgressBar) uiComponent;
boolean first = true;
String height = progressBar.getHeight();
if (height != null) {
encodeHeight(responseWriter, progressBar, height, first);
first = false;
}
String label = progressBar.getLabel();
if (label != null) {
encodeLabel(responseWriter, progressBar, label, first);
first = false;
}
String layout = progressBar.getLayout();
if (layout != null) {
encodeOrientation(responseWriter, progressBar, layout, first);
first = false;
}
Integer maxProgress = progressBar.getMaxProgress();
if (maxProgress != null) {
encodeMax(responseWriter, progressBar, maxProgress, first);
first = false;
}
Integer minProgress = progressBar.getMinProgress();
if (minProgress != null) {
encodeMin(responseWriter, progressBar, minProgress, first);
first = false;
}
Integer value = progressBar.getValue();
if (value != null) {
encodeValue(responseWriter, progressBar, value, first);
first = false;
}
String width = progressBar.getWidth();
if (width != null) {
encodeWidth(responseWriter, progressBar, width, first);
first = false;
}
encodeHiddenAttributes(facesContext, responseWriter, progressBar, first);
}
use of com.liferay.faces.alloy.component.progressbar.ProgressBar in project liferay-faces-alloy by liferay.
the class ProgressBarRenderer method encodeJavaScript.
/**
* This method is being overridden in order to set the value of the progressBar when server-side polling occurs.
* Otherwise, this method simply calls super.encodeJavaScript() in order to render the component normally.
*/
@Override
public void encodeJavaScript(FacesContext facesContext, UIComponent uiComponent) throws IOException {
if (isAjaxPolling(facesContext, uiComponent)) {
ProgressBar progressBar = (ProgressBar) uiComponent;
String clientVarName = getClientVarName(facesContext, progressBar);
String clientKey = progressBar.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
// Buffer all JavaScript so that it is rendered in the <eval> section of the partial response.
BufferedScriptResponseWriter bufferedScriptResponseWriter = new BufferedScriptResponseWriter();
String clientId = progressBar.getClientId(facesContext);
String hiddenClientId = clientId.concat(HIDDEN_SUFFIX);
// J-
// Liferay.component('clientKey')
// J+
JavaScriptFragment liferayComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
Integer value = progressBar.getValue();
// J-
// LFAI.setProgressBarServerValue('hiddenClientId', Liferay.component('clientKey'), value);
// J+
encodeFunctionCall(bufferedScriptResponseWriter, "LFAI.setProgressBarServerValue", hiddenClientId, liferayComponent, value);
FacesRequestContext facesRequestContext = FacesRequestContext.getCurrentInstance();
facesRequestContext.addScript(bufferedScriptResponseWriter.toString());
} else {
super.encodeJavaScript(facesContext, uiComponent);
}
}
use of com.liferay.faces.alloy.component.progressbar.ProgressBar in project liferay-faces-alloy by liferay.
the class ProgressBarRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
ProgressBar progressBar = (ProgressBar) uiComponent;
String clientVarName = getClientVarName(facesContext, progressBar);
String clientKey = progressBar.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
Map<String, List<ClientBehavior>> clientBehaviorMap = progressBar.getClientBehaviors();
List<ClientBehavior> pollEventClientBehaviors = clientBehaviorMap.get("poll");
// If the developer has specified <f:ajax event="poll" />, then
String javaScriptText = "Liferay.component('".concat(clientKey).concat("')");
if ((pollEventClientBehaviors != null) && !pollEventClientBehaviors.isEmpty()) {
// Build up an anonymous function, which contains all clientBehaviors for the "poll" event, so that it can
// be passed to LFAI.initProgressBarServerMode().
// J-
// function(pollingFunction) {
// var event = null;
// jsf.ajax.request('clientId', event, 'poll', {
// render: 'clientId ' + render,
// execute: 'clientId ' + execute,
// onevent: function(data){
// if(data.status==='success'){
// pollingFunction();
// }
// onevent();
// },
// onerror: function(data){
// Liferay.component('clientKey').stopPolling();
// onerror();
// }
// });
// jsf.ajax.request(...);
// ...
// jsf.ajax.request(...);
// }
// J+
StringBuilder buf = new StringBuilder();
buf.append("function(pollingFunction){");
// ClientBehavior.getScript(ClientBehaviorContext clientBehaviorContext) renders javascript which expects a
// javascript variable named 'event' to have been initilized and contain the DOM event which triggered the
// request. Since there is no DOM event which triggers the progressBar events, render javascript
// initializing event to null;
buf.append("var event = null;");
String clientId = progressBar.getClientId(facesContext);
ClientBehaviorContext clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, progressBar, "poll", clientId, null);
int size = pollEventClientBehaviors.size();
// J-
// Liferay.component('clientKey')
// J+
JavaScriptFragment liferayComponent = new JavaScriptFragment(javaScriptText);
// It is possible to specify multiple <f:ajax event="poll" /> tags (even though there is no benefit).
for (int i = 0; i < size; i++) {
ClientBehavior pollEventClientBehavior = pollEventClientBehaviors.get(i);
if (i == 0) {
AjaxBehavior firstPollEventAjaxBehavior = (AjaxBehavior) pollEventClientBehavior;
String stopPollingFunction = "function(){".concat(liferayComponent.toString()).concat(".stopPolling();}");
// Ensure that render is '@this', execute is '@this', the pollingFunction is called onsuccess, and
// the stopPolling function is called onerror.
pollEventClientBehavior = new ProgressBarAjaxBehavior(firstPollEventAjaxBehavior, "pollingFunction", stopPollingFunction);
}
buf.append(pollEventClientBehavior.getScript(clientBehaviorContext));
buf.append(";");
}
buf.append("}");
JavaScriptFragment anonymousFunction = new JavaScriptFragment(buf.toString());
Integer pollingDelay = progressBar.getPollingDelay();
// J-
// LFAI.initProgressBarServerMode(Liferay.component('clientKey'), 'clientId', pollingDelay,
// function(pollingFunction) {
// var event = null;
// jsf.ajax.request('clientId', event, 'poll', {
// render: 'clientId ' + render,
// execute: 'clientId ' + execute,
// onevent: function(data){
// if(data.status==='success'){
// pollingFunction();
// }
// onevent();
// },
// onerror: function(data){
// Liferay.component('clientKey').stopPolling();
// onerror();
// }
// });
// jsf.ajax.request(...);
// ...
// jsf.ajax.request(...);
// }
// );
// J+
encodeFunctionCall(responseWriter, "LFAI.initProgressBarServerMode", liferayComponent, clientId, pollingDelay, anonymousFunction);
} else // Otherwise the component is in client mode.
{
// J-
// LFAI.initProgressBarClientMode(Liferay.component('clientKey'), projectStageDevelopment);
// J+
JavaScriptFragment liferayComponent = new JavaScriptFragment(javaScriptText);
encodeFunctionCall(responseWriter, "LFAI.initProgressBarClientMode", liferayComponent);
}
}
use of com.liferay.faces.alloy.component.progressbar.ProgressBar in project liferay-faces-alloy by liferay.
the class ProgressBarRenderer method isServerPollingEnabled.
private boolean isServerPollingEnabled(UIComponent uiComponent) {
ProgressBar progressBar = (ProgressBar) uiComponent;
Map<String, List<ClientBehavior>> clientBehaviorMap = progressBar.getClientBehaviors();
List<ClientBehavior> clientBehaviorsForPolling = clientBehaviorMap.get("poll");
return ((clientBehaviorsForPolling != null) && !clientBehaviorsForPolling.isEmpty());
}
Aggregations