Author: abelevich
Date: 2010-03-26 10:29:20 -0400 (Fri, 26 Mar 2010)
New Revision: 16672
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/faces-config.xml
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
Log:
refactoring
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/faces-config.xml
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/faces-config.xml 2010-03-26
14:27:21 UTC (rev 16671)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/faces-config.xml 2010-03-26
14:29:20 UTC (rev 16672)
@@ -33,4 +33,5 @@
<cdk:generate
xmlns:cdk="http://richfaces.org/cdk/extensions">false</cd...
</component-extension>
</component>
+
</faces-config>
\ No newline at end of file
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java 2010-03-26
14:27:21 UTC (rev 16671)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java 2010-03-26
14:29:20 UTC (rev 16672)
@@ -1,7 +1,5 @@
package org.richfaces.component;
-import java.util.Collection;
-import java.util.LinkedHashSet;
import java.util.Map;
import javax.el.ELException;
@@ -15,9 +13,11 @@
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ComponentSystemEvent;
import javax.faces.event.FacesEvent;
import org.ajax4jsf.Messages;
+import org.ajax4jsf.component.IterationStateHolder;
import org.ajax4jsf.renderkit.RendererUtils;
import org.richfaces.component.util.MessageUtil;
import org.richfaces.event.DataScrollerEvent;
@@ -26,25 +26,18 @@
import org.richfaces.log.RichfacesLogger;
import org.slf4j.Logger;
-
-public class UIDataScroller extends UIComponentBase implements DataScrollerSource {
+public class UIDataScroller extends UIComponentBase implements DataScrollerSource,
IterationStateHolder {
public static final String COMPONENT_TYPE = "org.richfaces.DataScroller";
public static final String COMPONENT_FAMILY = "org.richfaces.DataScroller";
+
+ public static final String SCROLLER_STATE_ATTRIBUTE = COMPONENT_TYPE +
":page";
private static final Logger log = RichfacesLogger.COMPONENTS.getLogger();
+
+ private Integer page;
- protected enum PropertyKeys {
- boundaryControls, data, fastControls, fastStep, forComponent, handleValue,
inactiveStyle, selectStyle,
- inactiveStyleClass, selectStyleClass, scrollerListener, lastPageMode, maxPages,
pageIndexVar, pagesVar, renderIfSinglePage,
- style, styleClass, stepControls
- }
-
- protected enum PageMode {
- full, part //part - prev short
- }
-
public static final String FIRST_FACET_NAME = "first";
public static final String LAST_FACET_NAME = "last";
@@ -58,11 +51,16 @@
public static final String LAST_DISABLED_FACET_NAME = "last_disabled";
-
-//TODO: anton - fix
- private Integer page;
-
-
+ protected enum PropertyKeys {
+ boundaryControls, data, fastControls, fastStep, forComponent, handleValue,
inactiveStyle, selectStyle,
+ inactiveStyleClass, selectStyleClass, scrollerListener, lastPageMode, maxPages,
pageIndexVar, pagesVar, renderIfSinglePage,
+ style, styleClass, stepControls
+ }
+
+ protected enum PageMode {
+ full, part //part - prev short
+ }
+
public void addScrollerListener(DataScrollerListener listener) {
addFacesListener(listener);
}
@@ -84,15 +82,20 @@
updateModel(dataScrollerEvent.getPage());
- FacesContext context = getFacesContext();
+ FacesContext facesContext = getFacesContext();
MethodExpression scrollerListener =
(MethodExpression)getStateHelper().eval(PropertyKeys.scrollerListener);
if (scrollerListener != null) {
- scrollerListener.invoke(context.getELContext(), new Object[]{event});
+ scrollerListener.invoke(facesContext.getELContext(), new Object[]{event});
}
- context.getPartialViewContext().getRenderIds().add(dataScrollerEvent.getComponent().getClientId(context));
-
context.getPartialViewContext().getRenderIds().add(getDataTable().getClientId(context));
+ facesContext.getPartialViewContext().getRenderIds().add(dataScrollerEvent.getComponent().getClientId(facesContext));
+
+ String dataTableId = getDataTable().getClientId(facesContext);
+
+ facesContext.getPartialViewContext().getRenderIds().add(dataTableId);
+ facesContext.getPartialViewContext().getExecuteIds().add(dataTableId);
+
}
}
@@ -261,9 +264,6 @@
return true;
}
-
-
-
public void setupFirstRowValue() {
UIComponent dataTable = getDataTable();
if (isRendered()) {
@@ -281,15 +281,15 @@
}
if (newPage != -1) {
- FacesContext context = getFacesContext();
- Object label = MessageUtil.getLabel(context, this);
+ FacesContext facesContext = getFacesContext();
+ Object label = MessageUtil.getLabel(facesContext, this);
String formattedMessage = Messages.getMessage(Messages.DATASCROLLER_PAGE_MISSING,
new Object[] {label, page, pageCount, newPage});
log.warn(formattedMessage);
page = newPage;
- dataTable.getAttributes().put(SCROLLER_STATE_ATTRIBUTE, page);
+ dataTable.getAttributes().put(dataTable.getClientId(facesContext)+
SCROLLER_STATE_ATTRIBUTE, page);
}
if (isRendered(dataTable)) {
@@ -322,8 +322,12 @@
}
public int getPage() {
- Map<String, Object> attributes = getDataTable().getAttributes();
- Integer state = (Integer) attributes.get(SCROLLER_STATE_ATTRIBUTE);
+ UIComponent dataTable = getDataTable();
+ Map<String, Object> attributes = getDataTable().getAttributes();
+
+ FacesContext facesContext = getFacesContext();
+ Integer state = (Integer) attributes.get(dataTable.getClientId(facesContext)+
SCROLLER_STATE_ATTRIBUTE);
+
if (state != null) {
return state;
}
@@ -335,37 +339,36 @@
ValueExpression ve = getValueExpression("page");
if (ve != null) {
try {
- Integer pageObject = (Integer) ve.getValue(getFacesContext().getELContext());
+ Integer pageObject = (Integer) ve.getValue(facesContext.getELContext());
if (pageObject != null) {
return pageObject;
- } else {
- return 1;
}
} catch (ELException e) {
throw new FacesException(e);
}
- } else {
- return 1;
- }
+ }
+
+ return 1;
}
private void updateModel(int newPage) {
- UIComponent dataTable = getDataTable();
-
- if (isRendered(dataTable)) {
+
+ FacesContext facesContext = getFacesContext();
+ UIComponent dataTable = getDataTable();
+
+ if (isRendered(dataTable)) {
dataTable.getAttributes().put("first", (newPage - 1) *
getRows(dataTable));
}
-
+
Map<String, Object> attributes = dataTable.getAttributes();
- attributes.put(SCROLLER_STATE_ATTRIBUTE, newPage);
+ attributes.put(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE,
newPage);
- FacesContext context = getFacesContext();
ValueExpression ve = getValueExpression("page");
if (ve != null) {
try {
- ve.setValue(context.getELContext(), newPage);
- attributes.remove(SCROLLER_STATE_ATTRIBUTE);
+ ve.setValue(facesContext.getELContext(), newPage);
+ attributes.remove(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE);
} catch (ELException e) {
String messageStr = e.getMessage();
Throwable result = e.getCause();
@@ -377,33 +380,33 @@
FacesMessage message;
if (null == messageStr) {
message =
- MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID,
+ MessageUtil.getMessage(facesContext, UIInput.UPDATE_MESSAGE_ID,
new Object[] { MessageUtil.getLabel(
- context, this) });
+ facesContext, this) });
} else {
message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
messageStr,
messageStr);
}
- context.getExternalContext().log(message.getSummary(), result);
- context.addMessage(getClientId(context), message);
- context.renderResponse();
+ facesContext.getExternalContext().log(message.getSummary(), result);
+ facesContext.addMessage(getClientId(facesContext), message);
+ facesContext.renderResponse();
} catch (IllegalArgumentException e) {
FacesMessage message =
- MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID,
+ MessageUtil.getMessage(facesContext, UIInput.UPDATE_MESSAGE_ID,
new Object[] { MessageUtil.getLabel(
- context, this) });
- context.getExternalContext().log(message.getSummary(), e);
- context.addMessage(getClientId(context), message);
- context.renderResponse();
+ facesContext, this) });
+ facesContext.getExternalContext().log(message.getSummary(), e);
+ facesContext.addMessage(getClientId(facesContext), message);
+ facesContext.renderResponse();
} catch (Exception e) {
FacesMessage message =
- MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID,
+ MessageUtil.getMessage(facesContext, UIInput.UPDATE_MESSAGE_ID,
new Object[] { MessageUtil.getLabel(
- context, this) });
- context.getExternalContext().log(message.getSummary(), e);
- context.addMessage(getClientId(context), message);
- context.renderResponse();
+ facesContext, this) });
+ facesContext.getExternalContext().log(message.getSummary(), e);
+ facesContext.addMessage(getClientId(facesContext), message);
+ facesContext.renderResponse();
}
}
}
@@ -446,24 +449,17 @@
}
}
}
-
- public Object saveState(FacesContext context) {
- return new Object[] {
- super.saveState(context),
- page
- };
-
+
+ public Object saveState(FacesContext facesContext) {
+ return new Object[] { super.saveState(facesContext), page };
}
- public void restoreState(FacesContext context, Object object) {
+ public void restoreState(FacesContext facesContext, Object object) {
Object[] state = (Object[]) object;
-
- super.restoreState(context, state[0]);
+ super.restoreState(facesContext, state[0]);
page = (Integer) state[1];
}
- public static final String SCROLLER_STATE_ATTRIBUTE = COMPONENT_TYPE +
":page";
-
public boolean isLocalPageSet() {
return page != null;
}
@@ -471,9 +467,34 @@
public void resetLocalPage() {
page = null;
}
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ @Override
+ public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
+ super.processEvent(event);
+ }
@Override
- public String getFamily() {
- return COMPONENT_FAMILY;
+ public Object getIterationState() {
+ FacesContext facesContext = getFacesContext();
+ UIComponent dataTable = getDataTable();
+ Integer page =
(Integer)dataTable.getAttributes().get(dataTable.getClientId(facesContext) +
SCROLLER_STATE_ATTRIBUTE);
+ Object [] stateObject = page != null ? new Object[]{page} : null;
+ return stateObject;
}
+
+ @Override
+ public void setIterationState(Object stateObject) {
+ if (stateObject != null) {
+ Object[] state = (Object[]) stateObject;
+ FacesContext facesContext = getFacesContext();
+ UIComponent dataTable = getDataTable();
+ dataTable.getAttributes().put(dataTable.getClientId(facesContext) +
SCROLLER_STATE_ATTRIBUTE, state[0]);
+ }
+ }
+
}
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java 2010-03-26
14:27:21 UTC (rev 16671)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java 2010-03-26
14:29:20 UTC (rev 16672)
@@ -13,15 +13,15 @@
public String getFastControls() {
return (String)getStateHelper().eval(PropertyKeys.fastControls,
"show");
}
+
+ public String getFor() {
+ return (String)getStateHelper().eval(PropertyKeys.forComponent);
+ }
public int getFastStep() {
return (Integer)getStateHelper().eval(PropertyKeys.fastStep, 0);
}
- public String getFor() {
- return (String)getStateHelper().eval(PropertyKeys.forComponent);
- }
-
public String getInactiveStyle() {
return (String)getStateHelper().eval(PropertyKeys.inactiveStyle);
}
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-03-26
14:27:21 UTC (rev 16671)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-03-26
14:29:20 UTC (rev 16672)
@@ -23,13 +23,11 @@
import java.io.IOException;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
@@ -53,6 +51,7 @@
@ResourceDependency(name = "css/datascroller.css")
})
+
public class DataScrollerBaseRenderer extends RendererBase {
public void doDecode(FacesContext context, UIComponent component) {
@@ -75,7 +74,6 @@
public ControlsState getControlsState(FacesContext context, UIComponent component) {
-
int fastStep = (Integer)component.getAttributes().get("fastStep");
int pageIndex = (Integer)component.getAttributes().get("page");
int pageCount = (Integer)component.getAttributes().get("pageCount");
@@ -207,9 +205,9 @@
out.startElement(HTML.SPAN_ELEM, component);
if (isCurrentPage) {
- out.writeAttribute(HTML.CLASS_ATTRIBUTE, "ds_digital ds_current
"+styleClass, null);
+ out.writeAttribute(HTML.CLASS_ATTRIBUTE, "ds_digital ds_current
" + styleClass, null);
} else {
- out.writeAttribute(HTML.CLASS_ATTRIBUTE, "ds_digital
"+styleClass, null);
+ out.writeAttribute(HTML.CLASS_ATTRIBUTE, "ds_digital " +
styleClass, null);
}
if (null != style) {
@@ -218,10 +216,12 @@
String page = Integer.toString(i + 1);
String id = clientId+ "_ds_" + page;
+
out.writeAttribute(HTML.ID_ATTRIBUTE,id, null);
+
digital.put(id, page);
- out.writeText(page, null);
+ out.writeText(page, null);
out.endElement(HTML.SPAN_ELEM);
}
@@ -271,6 +271,7 @@
options.put("buttons", buttons);
options.put("digitals", digitals);
options.put("currentPage",
(Integer)component.getAttributes().get("page"));
+
function.addParameter(getSubmitFunction(context, component));
function.addParameter(options);
@@ -295,47 +296,6 @@
return definition;
}
- public void renderPages(FacesContext context, UIComponent component, int pageIndex,
int count) throws IOException {
- int currentPage = pageIndex;
-
- int pageCount = count;
- if (pageCount <= 1) {
- pageCount = 1;
- }
- String varName = (String)
component.getAttributes().get("pageIndexVar");
- if (varName != null && varName.length() > 0) {
- //TODO: anton - fix
- context.getExternalContext().getRequestMap().put(varName, new
Integer(currentPage));
- }
- varName = (String) component.getAttributes().get("pagesVar");
- if (varName != null && varName.length() > 0) {
- //TODO: anton - fix
- context.getExternalContext().getRequestMap().put(varName, new
Integer(pageCount));
- }
- }
-
- //get UIParameter's Map
- protected Map <String, Object> getParameters(FacesContext context, UIComponent
component){
- Map <String,Object> parameters = new HashMap<String, Object>();
-
- if(component instanceof UIDataScroller){
-
- UIDataScroller datascroller = (UIDataScroller)component;
- List <UIComponent> children = datascroller.getChildren();
-
- for (UIComponent child: children) {
- if(child instanceof UIParameter) {
- UIParameter param = (UIParameter)child;
- String name = param.getName();
- if (name != null) {
- parameters.put(name, param.getValue());
- }
- }
- }
- }
- return parameters;
- }
-
public boolean getRendersChildren() {
return true;
}