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 2006/03/04 09:41:08 UTC
svn commit: r383078 -
/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java
Author: mmarinschek
Date: Sat Mar 4 00:41:06 2006
New Revision: 383078
URL: http://svn.apache.org/viewcvs?rev=383078&view=rev
Log:
reformatted renderer
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java?rev=383078&r1=383077&r2=383078&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java Sat Mar 4 00:41:06 2006
@@ -19,61 +19,69 @@
*/
public class SubFormRenderer extends HtmlRenderer
{
- private static final String SUBMIT_FUNCTION_SUFFIX = "_submit";
- private static final String HIDDEN_PARAM_NAME = "org.apache.myfaces.custom.subform.submittedId";
-
- public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
+ private static final String SUBMIT_FUNCTION_SUFFIX = "_submit";
+ private static final String HIDDEN_PARAM_NAME = "org.apache.myfaces.custom.subform.submittedId";
+
+ public void encodeBegin(FacesContext context, UIComponent component) throws IOException
+ {
super.encodeBegin(context, component);
-
+
ResponseWriter writer = context.getResponseWriter();
-
+
HtmlRendererUtils.writePrettyLineSeparator(context);
writer.startElement(HTML.SCRIPT_ELEM, null);
- writer.writeAttribute(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_ATTR,org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT,null);
-
+ writer.writeAttribute(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_ATTR, org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
+
UIForm parentForm = findParentForm(component);
writer.writeText(createPartialSubmitJS(component.getId(), parentForm.getClientId(context)), null);
-
+
writer.endElement(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_ELEM);
- HtmlRendererUtils.writePrettyLineSeparator(context);
+ HtmlRendererUtils.writePrettyLineSeparator(context);
}
- public void decode(FacesContext context, UIComponent component) {
+ public void decode(FacesContext context, UIComponent component)
+ {
super.decode(context, component);
-
+
Map paramValuesMap = context.getExternalContext().getRequestParameterMap();
- String reqValue = (String)paramValuesMap.get(HIDDEN_PARAM_NAME);
- if (reqValue != null && component.getId().equals(reqValue)) {
- ((SubForm)component).setSubmitted(true);
+ String reqValue = (String) paramValuesMap.get(HIDDEN_PARAM_NAME);
+ if (reqValue != null && component.getId().equals(reqValue))
+ {
+ ((SubForm) component).setSubmitted(true);
}
- }
+ }
+
/**
*
- */
- protected String createPartialSubmitJS(String subFormId, String parentFormClientId) {
+ */
+ protected String createPartialSubmitJS(String subFormId, String parentFormClientId)
+ {
StringBuffer script = new StringBuffer();
script.append("function ");
- script.append(subFormId+SUBMIT_FUNCTION_SUFFIX+"()");
- script.append(" {\n");
- script.append("var form = document.forms['"+parentFormClientId+"'];\n");
+ script.append(subFormId).append(SUBMIT_FUNCTION_SUFFIX + "()");
+ script.append(" {\n");
+ script.append("var form = document.forms['").append(parentFormClientId).append("'];\n");
script.append("var el = document.createElement(\"input\");\n");
script.append("el.type = \"hidden\";\n");
- script.append("el.name = \""+HIDDEN_PARAM_NAME+"\";\n");
- script.append("el.value = \""+subFormId+"\";\n");
- script.append("form.appendChild(el);\n");
- script.append("form.submit();\n");
- script.append("}\n");
-
+ script.append("el.name = \"" + HIDDEN_PARAM_NAME + "\";\n");
+ script.append("el.value = \"").append(subFormId).append("\";\n");
+ script.append("form.appendChild(el);\n");
+ script.append("form.submit();\n");
+ script.append("}\n");
+
return script.toString();
}
+
/**
*
*/
- protected UIForm findParentForm(UIComponent component) {
+ protected UIForm findParentForm(UIComponent component)
+ {
UIComponent parentComponent = component.getParent();
- while (!(parentComponent instanceof UIForm)) {
+ while (!(parentComponent instanceof UIForm))
+ {
parentComponent = parentComponent.getParent();
}
- return (UIForm)parentComponent;
+ return (UIForm) parentComponent;
}
}