You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by pr...@apache.org on 2005/11/02 20:54:26 UTC
svn commit: r330333 - in
/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom: ajax/api/
ajax/util/ inputAjax/
Author: prophecy
Date: Wed Nov 2 11:54:24 2005
New Revision: 330333
URL: http://svn.apache.org/viewcvs?rev=330333&view=rev
Log:
Minor updates and fixes
Modified:
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/api/AjaxDecodePhaseListener.java
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/api/AjaxPhaseListener.java
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/util/AjaxRendererUtils.java
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlInputTextAjaxRenderer.java
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectManyCheckboxAjax.java
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/api/AjaxDecodePhaseListener.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/api/AjaxDecodePhaseListener.java?rev=330333&r1=330332&r2=330333&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/api/AjaxDecodePhaseListener.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/api/AjaxDecodePhaseListener.java Wed Nov 2 11:54:24 2005
@@ -32,14 +32,13 @@
/**
* Some Ajax components might do special decoding at apply request values phase
*
- * @return PhaseId The AJAX phase listener will be invoked after the invoke application phase.
+ * @return PhaseId The AJAX decode phase listener will be invoked before apply request values phase.
*/
public PhaseId getPhaseId()
{
return PhaseId.APPLY_REQUEST_VALUES;
}
-
public void beforePhase(PhaseEvent event)
{
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/api/AjaxPhaseListener.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/api/AjaxPhaseListener.java?rev=330333&r1=330332&r2=330333&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/api/AjaxPhaseListener.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/api/AjaxPhaseListener.java Wed Nov 2 11:54:24 2005
@@ -98,40 +98,14 @@
try
{
// TR - What is this HtmlBufferResponseWriterWrapper stuff for???? This caused me hours and hours of pain
- boolean responseWriterWasNull = false;
- HtmlBufferResponseWriterWrapper wrapper = null;
if (context.getResponseWriter() == null)
{
- responseWriterWasNull = true;
- //wrapper = HtmlBufferResponseWriterWrapper.getInstance(null);
- //context.setResponseWriter(wrapper);
ServletResponse response = (ServletResponse) context.getExternalContext().getResponse();
Writer htmlResponseWriter = response.getWriter();
context.setResponseWriter(new HtmlResponseWriterImpl(htmlResponseWriter, "text/html", "UTF-8"));
}
((AjaxComponent) ajaxComponent).encodeAjax(context);
-
- /*if (responseWriterWasNull)
- {
- StringBuffer buf = new StringBuffer(wrapper.toString());
-
- buf.insert(0, Integer.toHexString(buf.length()) + "\r\n");
- buf.append("\r\n" + 0 + "\r\n\r\n");
-
- //todo: fix this to work in PortletRequest as well
- if (context.getExternalContext().getResponse() instanceof HttpServletResponse)
- {
- ((HttpServletResponse) context.getExternalContext().getResponse()).addHeader(
- "Transfer-Encoding", "chunked");
- PrintWriter writer = ((HttpServletResponse) context.getExternalContext().getResponse()).getWriter();
- // buf.delete(buf.indexOf("<"), buf.indexOf(">")+1);
- writer.print(buf.toString());
- //System.out.println("PhaseListener: buf = " + buf.toString());
- writer.flush();
- writer.close();
- }
- }*/
}
catch (IOException e)
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/util/AjaxRendererUtils.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/util/AjaxRendererUtils.java?rev=330333&r1=330332&r2=330333&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/util/AjaxRendererUtils.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/util/AjaxRendererUtils.java Wed Nov 2 11:54:24 2005
@@ -1,18 +1,3 @@
-/*
- * 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.ajax.util;
import org.apache.myfaces.component.html.util.AddResource;
@@ -75,7 +60,7 @@
public static void writeAjaxScript(FacesContext context, ResponseWriter out, AjaxCallbacks component, String extraParams) throws IOException
{
UIComponent uiComponent = (UIComponent) component;
- //String clientId = uiComponent.getClientId(context);
+ String clientId = uiComponent.getClientId(context);
String viewId = context.getViewRoot().getViewId();
ViewHandler viewHandler = context.getApplication().getViewHandler();
//String actionURL = viewHandler.getActionURL(context, viewId);
@@ -102,61 +87,51 @@
if (component.getOnStart() != null)
out.writeText("var " + jsNameSpace + "onStartFunction = " + component.getOnStart() + ";\n", null);
- // todo: stringbuffer this
StringBuffer buff = new StringBuffer();
- buff.append("\n" +
- "function " + jsNameSpace + "notifyElement(originalRequest, successful)\n" +
- "{\n" +
- " //alert(\"originalRequest: \" + originalRequest + \" - \" + successful + \"\\ntext: \" + originalRequest.responseText);\n" +
- " var errorArray = originalRequest.responseXML.getElementsByTagName(\"response\")[0].getElementsByTagName(\"error\");\n" +
- " if(errorArray && errorArray.length > 0){\n" +
+ buff.append("\n").append(
+ "function ").append(jsNameSpace).append("notifyElement(originalRequest, successful)\n").append(
+ "{\n").append(
+ " //alert(\"originalRequest: \" + originalRequest + \" - \" + successful + \"\\ntext: \" + originalRequest.responseText);\n").append(
+ " var errorArray = originalRequest.responseXML.getElementsByTagName(\"response\")[0].getElementsByTagName(\"error\");\n").append(
+ " if(errorArray && errorArray.length > 0){\n").append(
// could easily loop this and handle more than one error at a time, but that wouldn't happen now
- " var myObError = errorArray[0];\n" +
- " var errorClientId = myObError.getAttribute(\"elname\");\n" +
- " var errorSeverity = myObError.getAttribute(\"severity\");\n" +
- " var errorSummary = myObError.getAttribute(\"summary\");\n" +
- " " + jsNameSpace + "displayError(errorClientId, errorSeverity, errorSummary);\n" +
- " }\n" +
- " var myObElementArray = originalRequest.responseXML.getElementsByTagName(\"response\")[0].getElementsByTagName(\"elementUpdated\");\n" +
- " if(myObElementArray && myObElementArray.length > 0){" +
- " var myObElement = myObElementArray[0];\n" +
- " var elname = myObElement.getAttribute(\"elname\");\n" +
- " var elvalue = myObElement.getAttribute(\"elvalue\");\n" +
- " if (successful)\n" +
+ " var myObError = errorArray[0];\n").append(
+ " var errorClientId = myObError.getAttribute(\"elname\");\n").append(
+ " var errorSeverity = myObError.getAttribute(\"severity\");\n").append(
+ " var errorSummary = myObError.getAttribute(\"summary\");\n").append(
+ " ").append(jsNameSpace).append("displayError(errorClientId, errorSeverity, errorSummary);\n").append(
+ " }\n").append(
+ " var myObElementArray = originalRequest.responseXML.getElementsByTagName(\"response\")[0].getElementsByTagName(\"elementUpdated\");\n").append(
+ " if(myObElementArray && myObElementArray.length > 0){").append(
+ " var myObElement = myObElementArray[0];\n").append(
+ " var elname = myObElement.getAttribute(\"elname\");\n").append(
+ " var elvalue = myObElement.getAttribute(\"elvalue\");\n").append(
+ " if (successful)\n").append(
" {\n");
if (component.getOnSuccess() != null)
- buff.append(" " + jsNameSpace + "onSuccessFunction(elname, elvalue);\n");
- buff.append(" }\n" +
- " else\n" +
+ buff.append(" ").append(jsNameSpace).append("onSuccessFunction(elname, elvalue);\n");
+ buff.append(" }\n").append(
+ " else\n").append(
" {\n");
if (component.getOnFailure() != null)
- buff.append(" " + jsNameSpace + "onFailureFunction(elname, elvalue);\n");
- buff.append(" }\n" +
- " }\n" +
- "}\n" +
- "function " + jsNameSpace + "displayError(elname, severity, summary){\n" +
- " var msgSpan = document.getElementById(\"msg_\" + elname);\n" +
- " msgSpan.innerHTML = summary;\n" +
- "}\n" +
- "function " + jsNameSpace + "notifyElementFailure(originalRequest)\n" +
- "{\n" +
- " alert('failed');\n" +
- " " + jsNameSpace + "notifyElement(originalRequest, false);\n" +
- "}\n" +
- "function " + jsNameSpace + "notifyElementSuccess(originalRequest)\n" +
- "{\n" +
- " " + jsNameSpace + "notifyElement(originalRequest, true);\n" +
- "}\n" +
- "function " + jsNameSpace + "complete(originalRequest)\n" +
- "{\n" +
- " alert('completed'); \n" +
- "}\n" +
- "function " + jsNameSpace + "ajaxSubmit(f, elname)\n" +
- "{\n" +
- " var elvalue = f.value;\n");
+ buff.append(" ").append(jsNameSpace).append("onFailureFunction(elname, elvalue);\n");
+ buff.append(" }\n").append(" }\n").append("}\n");
+ buff.append("function ").append(jsNameSpace)
+ .append("displayError(elname, severity, summary){\n")
+ .append(" var msgSpan = document.getElementById(\"msg_\" + elname);\n")
+ .append(" msgSpan.innerHTML = summary;\n")
+ .append("}\n");
+ buff.append("function ").append(jsNameSpace).append("notifyElementFailure(originalRequest){\n")
+ .append(" ").append(jsNameSpace).append("notifyElement(originalRequest, false);\n" + "}\n");
+ buff.append("function ").append(jsNameSpace).append("notifyElementSuccess(originalRequest){\n")
+ .append(" ").append(jsNameSpace).append("notifyElement(originalRequest, true);\n");
+ buff.append("}\n" + "function ").append(jsNameSpace).append("complete(originalRequest){\n")
+ .append("}\n");
+ buff.append("function ").append(jsNameSpace).append("ajaxSubmit(f, elname){\n")
+ .append(" var elvalue = f.value;\n");
if (component.getOnStart() != null)
- buff.append(" " + jsNameSpace + "onStartFunction(elname, elvalue);\n");
+ buff.append(" ").append(jsNameSpace).append("onStartFunction(elname, elvalue);\n");
buff.append(" var pars = \"affectedAjaxComponent=\" + elname + \"&elname=\" + elname + \"&elvalue=\" + elvalue + \"");
buff.append("&\" + elname + \"=\" + elvalue + \"");
if (extraParams != null)
@@ -170,17 +145,14 @@
buff.append("\";\n");
//buff.append("alert('pars: ' + pars);");
- buff.append(" var "
- //+ uiComponent.getId()
- + "_ajaxRequest = new Ajax.Request(\n" +
- " " + jsNameSpace + "ajaxUrl,\n" +
- " {method: 'post'" +
- ", parameters: pars");
- buff.append(", onComplete: " + jsNameSpace + "complete");
+ buff.append(" var " + "_ajaxRequest = new Ajax.Request(\n")
+ .append(" ").append(jsNameSpace).append("ajaxUrl,\n")
+ .append(" {method: 'post'" + ", parameters: pars");
+ buff.append(", onComplete: ").append(jsNameSpace).append("complete");
//if (component.getOnSuccess() != null)
- buff.append(", onSuccess: " + jsNameSpace + "notifyElementSuccess");
+ buff.append(", onSuccess: ").append(jsNameSpace).append("notifyElementSuccess");
//if (component.getOnFailure() != null)
- buff.append(", onFailure: " + jsNameSpace + "notifyElementFailure");
+ buff.append(", onFailure: ").append(jsNameSpace).append("notifyElementFailure");
buff.append("} \n" +
" );\n" +
"}");
@@ -197,6 +169,15 @@
encodeAjax(context, component, null);
}
+ /**
+ * Outputs elementUpdate elements with the client id and value.
+ * Also outputs error elements.
+ *
+ * @param context
+ * @param component
+ * @param extraReturnAttributes
+ * @throws IOException
+ */
public static void encodeAjax(FacesContext context, UIComponent component, Map extraReturnAttributes) throws IOException
{
String clientId = component.getClientId(context);
@@ -210,61 +191,46 @@
response.setContentType("text/xml");
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
- // this is all pretty wacky because it wasn't returning anything, turns out to be the OutputWrapper in AjaxPhaseListener!!! man oh man, countless hours wasted
- StringWriter sw = new StringWriter();
- PrintWriter buff = new PrintWriter(sw);
- // todo: remove concats
- buff.println("<?xml version=\"1.0\"?>");
- buff.println("<response>");
- buff.println();
+
+ StringBuffer buff = new StringBuffer();
+ buff.append("<?xml version=\"1.0\"?>");
+ buff.append("<response>");
+ // send error messages
+ boolean hasErrorMessages = false;
Iterator iter = context.getMessages(clientId);
while (iter.hasNext())
{
FacesMessage msg = (FacesMessage) iter.next();
- buff.write("<error elname=\"");
- buff.write(request.getParameter("elname"));
- buff.write("\" severity=\"");
- buff.write(msg.getSeverity().toString());
- buff.write("\" summary=\"");
- buff.write(msg.getSummary());
- buff.write("\" />");
- buff.println();
+ buff.append("<error elname=\"").append(request.getParameter("elname"))
+ .append("\" severity=\"").append(msg.getSeverity().toString())
+ .append("\" summary=\"").append(msg.getSummary())
+ .append("\" />");
+ buff.append("\n");
+ hasErrorMessages = true;
}
- buff.write("<elementUpdated elname=\"");
- buff.write(request.getParameter("elname"));
- buff.write("\" elvalue=\"");
- buff.write(request.getParameter("elvalue"));
- buff.write("\"");
- if (extraReturnAttributes != null)
+ if (!hasErrorMessages)
{
- Iterator iter2 = extraReturnAttributes.keySet().iterator();
- while (iter2.hasNext())
+ // send elementUpdated messages
+ buff.append("<elementUpdated elname=\"").append(request.getParameter("elname"));
+ buff.append("\" elvalue=\"").append(request.getParameter("elvalue")).append("\"");
+ if (extraReturnAttributes != null)
{
- String key = (String) iter2.next();
- buff.write(" ");
- buff.write(key);
- buff.write("=\"");
- buff.write(extraReturnAttributes.get(key).toString());
- buff.write("\"");
+ Iterator iter2 = extraReturnAttributes.keySet().iterator();
+ while (iter2.hasNext())
+ {
+ String key = (String) iter2.next();
+ buff.append(" ").append(key).append("=\"").append(extraReturnAttributes.get(key).toString()).append("\"");
+ }
}
+ buff.append(" />");
+ buff.append("\n");
}
-
- buff.write(" />");
- buff.println();
- buff.println("</response>");
- String output = sw.toString();
+ buff.append("</response>");
+ String output = buff.toString();
log.debug(output);
PrintWriter out = response.getWriter();
out.print(output);
out.flush();
-
-
- /* out.println("<?xml version=\"1.0\"?>");
- out.println("<response>");
- out.println("<elementUpdated elname=\"" + request.getParameter("elname") + "\" elvalue=\"" +
- request.getParameter("elvalue") + "\" checked=\"" + request.getParameter("checked") + "\"/>");
- out.println("</response>");*/
-
}
}
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlInputTextAjaxRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlInputTextAjaxRenderer.java?rev=330333&r1=330332&r2=330333&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlInputTextAjaxRenderer.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlInputTextAjaxRenderer.java Wed Nov 2 11:54:24 2005
@@ -68,23 +68,23 @@
return;
}
- //String clientId = component.getClientId(context);
+ String clientId = component.getClientId(context);
HtmlInputTextAjax comp = (HtmlInputTextAjax) component;
//log.debug("setting onclick");
- comp.setOnchange(component.getId() + "_MyFaces_inputAjax_ajaxSubmit(this, '" + component.getId() + "');");
+ comp.setOnchange(component.getId() + "_MyFaces_inputAjax_ajaxSubmit(this, '" + clientId + "');");
this.encodeJavascript(context, component);
super.encodeEnd(context, component);
-
+
// output a span for error messages
- ResponseWriter writer = context.getResponseWriter();
+ ResponseWriter writer = context.getResponseWriter();
writer.startElement(HTML.SPAN_ELEM, component);
- writer.writeAttribute(HTML.ID_ATTR, "msg_" + component.getId(), null);
+ writer.writeAttribute(HTML.ID_ATTR, "msg_" + clientId, null);
writer.writeText(" ", null);
writer.endElement(HTML.SPAN_ELEM);
-
+
}
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectManyCheckboxAjax.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectManyCheckboxAjax.java?rev=330333&r1=330332&r2=330333&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectManyCheckboxAjax.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectManyCheckboxAjax.java Wed Nov 2 11:54:24 2005
@@ -1,18 +1,3 @@
-/*
- * 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.inputAjax;
import org.apache.myfaces.component.html.ext.HtmlSelectManyCheckbox;
@@ -34,6 +19,9 @@
import java.util.Map;
/**
+ * Current limitations
+ * - Bound value must be a Collection of Strings!
+ *
* @author Travis Reeder (latest modification by $Author: mmarinschek $)
* @version $Revision: 290397 $ $Date: 2005-09-20 10:35:09 +0200 (Di, 20 Sep 2005) $
*/