Author: maksimkaszynski
Date: 2007-06-07 07:50:51 -0400 (Thu, 07 Jun 2007)
New Revision: 1071
Added:
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/component/renderkit/
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/component/renderkit/html/
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/component/renderkit/html/SelectionRendererContributorTest.java
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/model/
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/model/selection/
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/model/selection/ClientSelectionConverterTest.java
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/ClientSelectionConverter.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java
trunk/sandbox/scrollable-grid/src/main/templates/org/richfaces/scrollable-grid.jspx
Log:
added contributor to renderer
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java 2007-06-07
11:14:02 UTC (rev 1070)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java 2007-06-07
11:50:51 UTC (rev 1071)
@@ -43,6 +43,7 @@
public abstract class UIScrollableGrid extends UIRepeat implements AjaxComponent,
Sortable, Selectable{
+ public static final String COMPONENT_TYPE =
"org.richfaces.component.ScrollableGrid";
private transient Collection partialUpdateChildren;
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/ClientSelectionConverter.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/ClientSelectionConverter.java 2007-06-07
11:14:02 UTC (rev 1070)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/ClientSelectionConverter.java 2007-06-07
11:50:51 UTC (rev 1071)
@@ -12,7 +12,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.richfaces.component.UIScrollableGrid;
/**
* @author Maksim Kaszynski
@@ -27,11 +26,15 @@
LogFactory.getLog(ClientSelectionConverter.class);
public Object getAsObject(FacesContext context, UIComponent component, String value) {
- return getAsSelection(context, (UIScrollableGrid) component, value);
+ return getAsSelection(context, component, value == null ? "" : value);
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
+ if (log.isDebugEnabled()) {
+ log.debug("Converting to string " + value);
+ }
+
StringBuffer buffer = new StringBuffer();
Iterator iterator = ((ClientSelection) value).getRanges().iterator();
@@ -50,8 +53,12 @@
return buffer.toString();
}
- private ClientSelection getAsSelection(FacesContext context, UIScrollableGrid grid,
String stringSelection) {
+ private ClientSelection getAsSelection(FacesContext context, UIComponent grid, String
stringSelection) {
+ if (log.isDebugEnabled()) {
+ log.debug("parsing " + stringSelection);
+ }
+
final ClientSelection clientSelection = new ClientSelection();
String [] selections = stringSelection.split(";");
@@ -80,7 +87,6 @@
}
}
-
return clientSelection;
}
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-06-07
11:14:02 UTC (rev 1070)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-06-07
11:50:51 UTC (rev 1071)
@@ -38,6 +38,7 @@
*/
public abstract class ScrollableGridBaseRenderer extends CompositeRenderer {
+
private final String FOOTER_PART = "footer";
@@ -293,7 +294,11 @@
state.nextRow();
}
};
-
+
+ public ScrollableGridBaseRenderer() {
+ addContributor(new SelectionRendererContributor());
+ }
+
public String getJavaScriptVarName(FacesContext context, UIScrollableGrid grid) {
String id = grid.getBaseClientId(context);
return "Richfaces_ScrollableGrid_" + id.replaceAll("[^A-Za-z0-9_]",
"_");
@@ -544,11 +549,21 @@
writer.endElement("tbody");
writer.endElement("table");
+ GridRendererState.restoreState(context);
+ grid.setRowKey(null);
+
ajaxContext.setResponseData(grid.getResponseData());
ajaxContext.getAjaxRenderedAreas().remove(grid.getClientId(context));
GridScrollSettings options = createOptions(grid);
ajaxContext.getResponseDataMap().put("options", options);
grid.setRows(grid.getDefaultRows());
+
+
+ //Then call contributors to write additional HTML content
+ contributorsEncodeHere(context, grid);
+
+
+
}
private GridScrollSettings createOptions(UIScrollableGrid grid){
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java 2007-06-07
11:14:02 UTC (rev 1070)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java 2007-06-07
11:50:51 UTC (rev 1071)
@@ -29,7 +29,7 @@
* @author Maksim Kaszynski
*
*/
-public class SelectionRendererContributor implements RendererContributor {
+public class SelectionRendererContributor implements RendererContributor,
HTMLEncodingContributor {
public static final String CLIENT_SELECTION = "clientSelection";
@@ -69,6 +69,7 @@
+
final GridRendererState state =
GridRendererState.createState(context, grid);
@@ -149,6 +150,17 @@
return null;
}
+
+ public void encode(FacesContext context, UIComponent component)
+ throws IOException {
+
+ UIScrollableGrid grid = (UIScrollableGrid) component;
+
+ encodeSelection(context, grid);
+ writeSelection(context, grid);
+ }
+
+
//Decide whether to add new row to selection based on comparison with old one
private boolean shouldAddToSelection(int i, ClientSelection oldSelection,
ClientSelection newSelection) {
return false;
Modified:
trunk/sandbox/scrollable-grid/src/main/templates/org/richfaces/scrollable-grid.jspx
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/templates/org/richfaces/scrollable-grid.jspx 2007-06-07
11:14:02 UTC (rev 1070)
+++
trunk/sandbox/scrollable-grid/src/main/templates/org/richfaces/scrollable-grid.jspx 2007-06-07
11:50:51 UTC (rev 1071)
@@ -167,6 +167,9 @@
<input type="hidden" name="#{clientId}_options_input"
id="#{clientId}_options_input"/>
<input type="hidden" name="#{clienId}_rows_input"
id="#{clientId}_rows_input" value="#{rows_count}"/>
<input type="button" name="#{clientId}_submit_input"
id="#{clientId}_submit_input"
onclick="#{this:getRowsAjaxUpdate(context,component)}"
style="display:none"/>
+
+ <f:call name="contributorsEncodeHere"/>
+
</div>
<f:call name="tearDownState"/>
Added:
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/component/renderkit/html/SelectionRendererContributorTest.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/component/renderkit/html/SelectionRendererContributorTest.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/component/renderkit/html/SelectionRendererContributorTest.java 2007-06-07
11:50:51 UTC (rev 1071)
@@ -0,0 +1,75 @@
+/**
+ *
+ */
+package org.richfaces.component.renderkit.html;
+
+import java.util.ArrayList;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.ExternalContext;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.shale.test.mock.MockExternalContext;
+import org.richfaces.component.UIScrollableGrid;
+import org.richfaces.model.selection.ClientSelection;
+import org.richfaces.renderkit.html.ScrollableGridBaseRenderer;
+import org.richfaces.renderkit.html.SelectionRendererContributor;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SelectionRendererContributorTest extends AbstractAjax4JsfTestCase {
+
+ private UIScrollableGrid component;
+ private SelectionRendererContributor contributor;
+ private ScrollableGridBaseRenderer renderer;
+
+ public SelectionRendererContributorTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ component = (UIScrollableGrid)
application.createComponent(UIScrollableGrid.COMPONENT_TYPE);
+ component.setValue(new ArrayList());
+ facesContext.getViewRoot().getChildren().add(component);
+ contributor = new SelectionRendererContributor();
+ renderer = new ScrollableGridBaseRenderer(){
+ protected Class getComponentClass() {
+ return UIScrollableGrid.class;
+ }};
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ this.component = null;
+ this.contributor = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.renderkit.html.SelectionRendererContributor#decode(javax.faces.context.FacesContext,
javax.faces.component.UIComponent, org.richfaces.renderkit.CompositeRenderer)}.
+ */
+ public void testDecode() {
+ MockExternalContext mockExternalContext =
+ (MockExternalContext) facesContext.getExternalContext();
+ String name =
+ SelectionRendererContributor.getSelectionInputName(facesContext, (UIScrollableGrid)
component);
+
+ String value = "";
+
+ mockExternalContext.addRequestParameterMap(name, value);
+
+ contributor.decode(facesContext, component, renderer);
+
+ Object selection = component.getSelection();
+
+ }
+
+}
Added:
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/model/selection/ClientSelectionConverterTest.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/model/selection/ClientSelectionConverterTest.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/model/selection/ClientSelectionConverterTest.java 2007-06-07
11:50:51 UTC (rev 1071)
@@ -0,0 +1,66 @@
+/**
+ *
+ */
+package org.richfaces.model.selection;
+
+import javax.faces.convert.Converter;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ClientSelectionConverterTest extends AbstractAjax4JsfTestCase {
+
+ private Converter converter;
+
+ /**
+ * @param name
+ */
+ public ClientSelectionConverterTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ converter = application.createConverter(ClientSelection.class);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ converter = null;
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.selection.ClientSelectionConverter#getAsObject(javax.faces.context.FacesContext,
javax.faces.component.UIComponent, java.lang.String)}.
+ */
+ public void testGetAsObject() {
+ fail("Not yet implemented"); // TODO
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.selection.ClientSelectionConverter#getAsString(javax.faces.context.FacesContext,
javax.faces.component.UIComponent, java.lang.Object)}.
+ */
+ public void testGetAsString() {
+
+ ClientSelection clientSelection = new ClientSelection();
+ clientSelection.addRange(new SelectionRange(2,3));
+ clientSelection.addRange(new SelectionRange(5,22));
+
+ String value = converter.getAsString(facesContext, null, clientSelection);
+
+ assertNotNull(value);
+ assertTrue(value.length() > 0);
+ assertEquals("2,3;5,22;", value);
+
+
+ }
+
+}