rich:progressBar does not work in my project
thomas-richfaces Jul 4, 2013 6:02 AMHello,
I have a jsf based application with jsf 1.2.12 and richfaces 3.3.2.SR1 and I want to integrate a rich:progressBar.
In my myxhtml.xhtml I implemented a server side rich:progressBar. With the javascript function enableProgressBar() (see myjavascript.js) for the onclick-event I want to enable the progessbar. But I can not see a polling (interval="2000") my server in debug mode.
When I set breakpoints in the functions AdmUserListViewBulkRemove::performDeletion() and ProgressBarBean:getCurrentValue(), first the function performDeletion() was called and after finishing the function getCurrentValue() was called.
How can I set my progessbar to the state 'enable'?
Thanks for your hints, Thomas
myxhtml.xhml:
<div xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:q="http://teamdev.com/quipukit"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
...
<a4j:outputPanel id="progressPanel">
<div class="formInputValue">
<rich:progressBar value="#{progressBar.currentValue}"
interval="2000" label="#{progressBar.currentValue}"
id="progressBarId" enabled="#{progressBar.enabled}" minValue="0"
maxValue="#{progressBar.maxValue}"
reRenderAfterComplete="progressPanel"
title="#{dialog['progess.title']}">
<h:outputText value="#{progressBar.label}" />
</rich:progressBar>
</div>
</a4j:outputPanel>
...
<h:commandButton type="submit"
styleClass="formButtonWidth" value="#{rb['commonbutton.confirm']}"
rendered="#{admUserListView.removeUser.startAction}"
onclick="enableProgressBar(this,'progressBarId'); return true;"
actionListener="#{admUserListView.removeUser.performDeletion}" />
...
</div>
myjavascript.js:
function findParentNode(element, tagName) {
tagName = tagName.toUpperCase();
while (element) {
var elementNodeName = element.nodeName;
if (elementNodeName) {
elementNodeName = elementNodeName.toUpperCase();
}
if (elementNodeName == tagName) {
break;
}
element = element.parentNode;
}
if (element != null) {
return element;
} else {
return null;
}
}
function enableProgressBar(element, componentId) {
var formName = findParentNode(element, "FORM");
$(formName.name + ":" + componentId).component.enable();
}
ProgressBarBean.java:
public class ProgressBarBean implements Serializable {
public static final String ENABLE = "progressEnable";
public static final String LABEL = "progressLabel";
public static final String CURRENT = "progressCurrent";
public static final String MAXVALUE = "progressMaxValue";
private Boolean enabled = false;
private Long current;
private String label;
private Integer maxValue;
private SessionBean sessionBean;
private void init() {
if (sessionBean == null) {
sessionBean = FacesContextUtil.getSessionBean();
}
enabled = (Boolean) sessionBean.getSessionObject(ENABLE);
enabled = enabled != null ? enabled : false;
maxValue = (Integer) sessionBean.getSessionObject(MAXVALUE);
}
public Long getCurrentValue() {
init();
if (enabled) {
current = (Long) sessionBean.getSessionObject(CURRENT);
if (current != null) {
return current;
}
}
if (maxValue == null) {
Long returnLong = Long.valueOf(-1);
return returnLong;
} else {
return Long.valueOf(101);
}
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public Boolean getEnabled() {
Boolean returnBoolean = enabled != null ? enabled : false;
return returnBoolean;
}
public void setLabel(String label) {
this.label = label;
}
public String getLabel() {
label = (String) sessionBean.getSessionObject(LABEL);
String returnString = label != null ? label : "";
return returnString;
}
public void setMaxValue(Integer maxValue) {
this.maxValue = maxValue;
}
public Integer getMaxValue() {
Integer returnInteger = maxValue != null ? maxValue : 0;
return returnInteger;
}
}
AdmUserListViewBulkRemove.java:
public class AdmUserListViewBulkRemove {
...
public void performDeletion(ActionEvent event) {
...
startProgress(getDatalist().size());
int current = 1;
for (User user : getGoodList().getDatalist()) {
setCurrentLabel(user.getName());
setCurrentValue(current);
current++;
}
endOfProgress();
...
}
...
/**
* set max value to progress bean using session object from session bean
* @param maxValue max value as {@link Integer}
*/
protected void setMaxValue(Integer maxValue) {
getSessionBean().setSessionObject(ProgressBarBean.MAXVALUE, maxValue);
}
/**
* set current value to progress bean using session object from session bean
* @param currentValue current value of progress as {@link Integer}
*/
protected void setCurrentValue(Integer currentValue) {
getSessionBean().setSessionObject(ProgressBarBean.CURRENT, Long.valueOf(currentValue));
}
/**
* set current label to progress bean using session object from session bean
* @param currentLabel label as {@link String}
*/
protected void setCurrentLabel(String currentLabel) {
getSessionBean().setSessionObject(ProgressBarBean.LABEL, currentLabel);
}
/**
* control usage of progress bar
* @param enable <code>true</code> progress is enabled, <code>false</code> otherwise
*/
protected void setEnabled(boolean enable) {
getSessionBean().setSessionObject(ProgressBarBean.ENABLE, Boolean.valueOf(enable));
}
/**
* finish progress of actions, clear session objects
*/
protected void endOfProgress() {
getSessionBean().getAttributes().remove(ProgressBarBean.CURRENT);
getSessionBean().getAttributes().remove(ProgressBarBean.LABEL);
getSessionBean().getAttributes().remove(ProgressBarBean.MAXVALUE);
getSessionBean().getAttributes().remove(ProgressBarBean.ENABLE);
setEnabled(false);
}
/**
* start progress of actions, set max values and enable bar
* @param maxValue max value as {@link Integer}
*/
protected void startProgress(Integer maxValue) {
setMaxValue(maxValue);
setEnabled(true);
}
}
faces-config.xml:
<?xml version="1.0"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
...
<component>
<component-type>com.mycompany.myproject.component.ProgressBar</component-type>
<component-class>com.mycompany.myproject.ui.forms.jsf.components.ProgressBar</component-class>
</component>
...
<managed-bean>
<managed-bean-name>progressBar</managed-bean-name>
<managed-bean-class>com.mycompany.myproject.ui.forms.ProgressBarBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
...
</faces-config>
-
faces-config.xml 795 bytes
-
AdmUserListViewBulkRemove.java.zip 840 bytes
-
ProgressBarBean.java.zip 795 bytes
-
myjavascript.js 559 bytes
-
myxhtml.xhml.zip 673 bytes