You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2005/08/24 14:05:28 UTC
svn commit: r239619 - in
/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/autoupdatedatatable:
AutoUpdateDataTableRenderer.java AutoUpdateDataTableTag.java
Author: mmarinschek
Date: Wed Aug 24 05:05:13 2005
New Revision: 239619
URL: http://svn.apache.org/viewcvs?rev=239619&view=rev
Log:
changes to make AJAX working with preserveDataModel=true
Modified:
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/autoupdatedatatable/AutoUpdateDataTableRenderer.java
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/autoupdatedatatable/AutoUpdateDataTableTag.java
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/autoupdatedatatable/AutoUpdateDataTableRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/autoupdatedatatable/AutoUpdateDataTableRenderer.java?rev=239619&r1=239618&r2=239619&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/autoupdatedatatable/AutoUpdateDataTableRenderer.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/autoupdatedatatable/AutoUpdateDataTableRenderer.java Wed Aug 24 05:05:13 2005
@@ -1,13 +1,28 @@
+/**
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.myfaces.custom.autoupdatedatatable;
import java.io.IOException;
+import org.apache.myfaces.util.StateUtils;
import javax.faces.application.StateManager;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-
import org.apache.myfaces.component.html.util.AddResource;
import org.apache.myfaces.custom.ajax.api.AjaxRenderer;
import org.apache.myfaces.renderkit.JSFAttr;
@@ -16,16 +31,24 @@
import org.apache.myfaces.renderkit.html.ext.HtmlTableRenderer;
/**
- * Created by IntelliJ IDEA.
- * User: ich
- * Date: 13.07.2005
- * Time: 19:46:00
- * To change this template use File | Settings | File Templates.
+ * @author Jörg Artaker
+ * @author Thomas Huber
+ * @version $Revision: $ $Date: $
+ * <p/>
+ * $Log: $
*/
public class AutoUpdateDataTableRenderer extends HtmlTableRenderer implements AjaxRenderer{
private static final String JAVASCRIPT_ENCODED = "org.apache.myfaces.autoupdatedatatable.JAVASCRIPT_ENCODED";
+ /**
+ * Encodes any stand-alone javascript functions that are needed. Uses either the extension filter, or a
+ * user-supplied location for the javascript files.
+ *
+ * @param context FacesContext
+ * @param component UIComponent
+ * @throws java.io.IOException
+ */
private void encodeJavascript(FacesContext context, UIComponent component) throws IOException
{
// check to see if javascript has already been written (which could happen if more than one tree on the same page)
@@ -33,7 +56,6 @@
{
return;
}
-
// render javascript function for client-side toggle (it won't be used if user has opted for server-side toggle)
ResponseWriter out = context.getResponseWriter();
String javascriptLocation = (String)component.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
@@ -53,16 +75,17 @@
context.getExternalContext().getRequestMap().put(JAVASCRIPT_ENCODED, Boolean.TRUE);
}
+ /**
+ * @param context FacesContext
+ * @param component UIComponent
+ * @throws java.io.IOException
+ */
public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
RendererUtils.checkParamValidity(context, component, AutoUpdateDataTable.class);
AutoUpdateDataTable autoUpdateDataTable = (AutoUpdateDataTable) component;
this.encodeJavascript(context,component);
-
- StateManager stateManager = context.getApplication().getStateManager();
- StateManager.SerializedView serializedView = stateManager.saveSerializedView(context);
-
super.encodeEnd(context, component);
ResponseWriter out = context.getResponseWriter();
@@ -71,19 +94,9 @@
ViewHandler viewHandler = context.getApplication().getViewHandler();
String actionURL = viewHandler.getActionURL(context, viewId);
-
- /**TODO this is way is not elegant, as it renders a copletely detached form element
- * also the state does not represent the state of each component
- */
-
- if (context.getApplication().getStateManager().isSavingStateInClient(context)){
- out.startElement(HTML.FORM_ELEM, null);
- context.getRenderKit().getResponseStateManager().writeState(context, serializedView);
- out.endElement(HTML.FORM_ELEM);
- }
-
out.startElement(HTML.SCRIPT_ELEM, null);
out.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+
out.writeText("new Ajax.PeriodicalUpdater('",null);
out.writeText(component.getClientId(context)+":tbody_element",null);
out.writeText("','",null);
@@ -92,24 +105,40 @@
if (context.getApplication().getStateManager().isSavingStateInClient(context)){
out.writeText(" , parameters: '&jsf_tree_64='+encodeURIComponent(document.getElementById('jsf_tree_64').value)+'&jsf_state_64='+encodeURIComponent(document.getElementById('jsf_state_64').value)+'&jsf_viewid='+encodeURIComponent(document.getElementById('jsf_viewid').value)", null);
}
- out.writeText(" })",null);
+ out.writeText(" })",null);
out.endElement(HTML.SCRIPT_ELEM);
- //System.out.println("autoUpdateDataTable.getFrequency() = " + autoUpdateDataTable.getFrequency());
-
-
}
+ /**
+ * @param facesContext FacesContext
+ * @param component UIComponent
+ */
public void decode(FacesContext facesContext, UIComponent component)
{
super.decode(facesContext, component);
}
-
-
+ /**
+ * @param context FacesContext
+ * @param component UIComponent
+ * @throws java.io.IOException
+ */
public void encodeAjax(FacesContext context, UIComponent component) throws IOException
{
encodeInnerHtml(context, component);
- }
+ if (context.getApplication().getStateManager().isSavingStateInClient(context)){
+ StateManager stateManager = context.getApplication().getStateManager();
+ StateManager.SerializedView serializedView = stateManager.saveSerializedView(context);
+ Object compStates = serializedView.getState();
+
+ StringBuffer buf = new StringBuffer();
+
+ buf.append("jsf_state=");
+ buf.append(StateUtils.encode64(compStates));
+ buf.append("jsf_state_end");
+ context.getResponseWriter().write(buf.toString());
+ }
+ }
}
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/autoupdatedatatable/AutoUpdateDataTableTag.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/autoupdatedatatable/AutoUpdateDataTableTag.java?rev=239619&r1=239618&r2=239619&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/autoupdatedatatable/AutoUpdateDataTableTag.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/autoupdatedatatable/AutoUpdateDataTableTag.java Wed Aug 24 05:05:13 2005
@@ -1,3 +1,18 @@
+/**
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.myfaces.custom.autoupdatedatatable;
import org.apache.myfaces.taglib.html.ext.HtmlDataTableTag;
@@ -7,31 +22,41 @@
import javax.faces.component.UIComponent;
/**
- * Created by IntelliJ IDEA.
- * User: ich
- * Date: 13.07.2005
- * Time: 19:16:58
- * To change this template use File | Settings | File Templates.
+ * @author Jörg Artaker
+ * @author Thomas Huber
+ * @version $Revision: $ $Date: $
+ * <p/>
+ * $Log: $
*/
public class AutoUpdateDataTableTag extends HtmlDataTableTag{
private static Log log = LogFactory.getLog(AutoUpdateDataTableTag.class);
-
private String _frequency;
+ /**
+ * @return the _frequency String
+ */
public String getFrequency() {
return _frequency;
}
+ /**
+ * @param _frequency String
+ */
public void setFrequency(String _frequency) {
this._frequency = _frequency;
}
-
+ /**
+ * @return the ComponentType String
+ */
public String getComponentType() {
return "org.apache.myfaces.AutoUpdateDataTable";
}
+ /**
+ * @return the RendererType String
+ */
public String getRendererType() {
return "org.apache.myfaces.AutoUpdateDataTable";
}
@@ -41,6 +66,9 @@
_frequency = null;
}
+ /**
+ * @param component UIComponent
+ */
protected void setProperties(UIComponent component) {
super.setProperties(component);