Author: nbelaevski
Date: 2009-02-10 14:33:19 -0500 (Tue, 10 Feb 2009)
New Revision: 12621
Removed:
trunk/ui/dataTable/src/main/resources/org/richfaces/renderkit/html/scripts/
Modified:
trunk/ui/dataTable/src/main/config/resources/resources-config.xml
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx
Log:
https://jira.jboss.org/jira/browse/RF-6021
Modified: trunk/ui/dataTable/src/main/config/resources/resources-config.xml
===================================================================
--- trunk/ui/dataTable/src/main/config/resources/resources-config.xml 2009-02-10 18:07:29
UTC (rev 12620)
+++ trunk/ui/dataTable/src/main/config/resources/resources-config.xml 2009-02-10 19:33:19
UTC (rev 12621)
@@ -3,4 +3,13 @@
<resource
class="org.richfaces.renderkit.html.iconimages.DataTableIconSortNone">
<name>org.richfaces.renderkit.html.iconimages.DataTableIconSortNone</name>
</resource>
+
+ <resource class="org.ajax4jsf.javascript.AjaxScript">
+ <name>org.ajax4jsf.javascript.AjaxScript</name>
+ </resource>
+
+ <resource class="org.ajax4jsf.javascript.PrototypeScript">
+ <name>org.ajax4jsf.javascript.PrototypeScript</name>
+ </resource>
+
</resource-config>
Modified:
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
---
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2009-02-10
18:07:29 UTC (rev 12620)
+++
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2009-02-10
19:33:19 UTC (rev 12621)
@@ -32,15 +32,19 @@
import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.component.UIDataAdaptor;
import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.AjaxScript;
import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.PrototypeScript;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.ajax4jsf.resource.InternetResource;
import org.richfaces.component.Column;
import org.richfaces.component.Row;
import org.richfaces.component.UIDataTable;
@@ -60,7 +64,14 @@
private static final String SORT_FILTER_PARAMETER = "fsp";
private static final String FILTER_INPUT_FACET_NAME = "filterValueInput";
+
+ private static final String REQUIRES_SCRIPTS_PARAMETER =
AbstractTableRenderer.class.getName() + ":REQUIRES_SCRIPTS";
+ private final InternetResource[] REQUIRED_SCRIPTS = new InternetResource[] {
+ getResource(PrototypeScript.class.getName()),
+ getResource(AjaxScript.class.getName())
+ };
+
/**
* Encode data table body
* @param context
@@ -502,23 +513,6 @@
return count;
}
- public void encodeScriptIfNecessary(FacesContext context, UIDataTable component) throws
IOException {
- boolean shouldRender = false;
- Iterator<UIComponent> columns = component.columns();
- while(columns.hasNext() && !shouldRender) {
- UIComponent next = columns.next();
- shouldRender = (next instanceof Column) && ((Column)next).isSortable();
- }
- if (shouldRender) {
- JSFunction function = new JSFunction("new RichFaces.DataTable");
- function.addParameter(component.getBaseClientId(context));
- ScriptOptions scriptOptions = new ScriptOptions(component);
- scriptOptions.addOption("sortMode", new JSFunction("new
RichFaces.SortMode.Single"));
- function.addParameter(scriptOptions);
- getUtils().writeScript(context, component, function.toScript());
- }
- }
-
@Override
protected void doDecode(FacesContext context, UIComponent component) {
Map<String, String> map = context.getExternalContext().getRequestParameterMap();
@@ -614,6 +608,10 @@
filterValueInput.setId(column.getId() + SORT_FILTER_PARAMETER);
filterValueInput.setImmediate(true);
column.getFacets().put(FILTER_INPUT_FACET_NAME, filterValueInput);
+
+ //Event.stop requires prototype.js
+ setRequiresScripts(context);
+
filterValueInput.getAttributes().put(HTML.onclick_ATTRIBUTE,
"Event.stop(event);");
filterValueInput.getAttributes().put(HTML.STYLE_CLASS_ATTR,
"rich-filter-input");
}
@@ -633,6 +631,10 @@
protected String buildAjaxFunction(FacesContext context, UIComponent column, boolean
sortable) {
UIComponent table = column.getParent();
String id = table.getClientId(context);
+
+ //Ajax submission requires scripts
+ setRequiresScripts(context);
+
JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(table, context);
Map<String, Object> eventOptions = AjaxRendererUtils.buildEventOptions(context,
table);
@@ -653,6 +655,36 @@
return buffer.toString();
}
+ protected void setRequiresScripts(FacesContext context) {
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, Object> requestMap = externalContext.getRequestMap();
+ if (requestMap.get(REQUIRES_SCRIPTS_PARAMETER) == null) {
+ requestMap.put(REQUIRES_SCRIPTS_PARAMETER, Boolean.TRUE);
+ }
+ }
+
+ protected boolean isRequiresScripts(FacesContext context) {
+ if (context == null) {
+
+ return false;
+ } else {
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, Object> requestMap = externalContext.getRequestMap();
+
+ return Boolean.TRUE.equals(requestMap.get(REQUIRES_SCRIPTS_PARAMETER));
+ }
+ }
+
+ @Override
+ protected InternetResource[] getScripts() {
+ InternetResource[] resources = null;
+ if (isRequiresScripts(FacesContext.getCurrentInstance())) {
+ resources = REQUIRED_SCRIPTS;
+ }
+
+ return resources;
+ }
+
protected class SimpleHeaderEncodeStrategy implements HeaderEncodeStrategy {
public void encodeBegin(FacesContext context, ResponseWriter writer,
Modified: trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx
===================================================================
--- trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx 2009-02-10
18:07:29 UTC (rev 12620)
+++ trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx 2009-02-10
19:33:19 UTC (rev 12621)
@@ -13,11 +13,6 @@
component="org.richfaces.component.UIDataTable"
<h:styles>css/table.xcss</h:styles>
- <h:scripts>
- new org.ajax4jsf.javascript.AjaxScript(),
- new org.ajax4jsf.javascript.PrototypeScript(),
- /org/richfaces/renderkit/html/scripts/data-table.js
- </h:scripts>
<f:clientid var="clientId"/>
<table id="#{clientId}"
class="dr-table rich-table #{component.attributes['styleClass']}"
style="#{component.attributes['style']}" >