You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/10/06 22:36:46 UTC
svn commit: r453759 -
/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/
Author: werpu
Date: Fri Oct 6 13:36:45 2006
New Revision: 453759
URL: http://svn.apache.org/viewvc?view=rev&rev=453759
Log:
major code cleanup, removed a lot of imports, fixed some dependencies into myfaces core, fixed some structural problems
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroup.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroupRenderer.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroupTag.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLink.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLinkRenderer.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLinkTag.java
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroup.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroup.java?view=diff&rev=453759&r1=453758&r2=453759
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroup.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroup.java Fri Oct 6 13:36:45 2006
@@ -16,7 +16,7 @@
package org.apache.myfaces.custom.toggle;
-import org.apache.myfaces.component.html.ext.HtmlPanelGroup;
+import javax.faces.component.html.HtmlPanelGroup;
/**
* Container class allows user to toggle between view/edit mode.
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroupRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroupRenderer.java?view=diff&rev=453759&r1=453758&r2=453759
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroupRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroupRenderer.java Fri Oct 6 13:36:45 2006
@@ -17,6 +17,8 @@
import java.io.IOException;
import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -26,28 +28,18 @@
import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlGroupRendererBase;
-import java.util.Iterator;
-import java.util.List;
-
-public class HtmlToggleGroupRenderer extends HtmlGroupRendererBase
-{
-
- private static Log log = LogFactory.getLog(HtmlToggleGroupRenderer.class);
+public class HtmlToggleGroupRenderer extends HtmlGroupRendererBase {
private static final String DISPLAY_NONE_STYLE = ";display:none;";
- public void encodeEnd(FacesContext context, UIComponent component)
- throws IOException
- {
- RendererUtils.checkParamValidity(context, component,
- HtmlToggleGroup.class);
+ public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
+ RendererUtils.checkParamValidity(context, component, HtmlToggleGroup.class);
boolean editMode = checkEditMode(component.getChildren());
toggleVisibility(component.getChildren(), editMode);
super.encodeEnd(context, component);
}
- private void toggleVisibility(List children, boolean editMode)
- {
+ private void toggleVisibility(List children, boolean editMode) {
Iterator it = children.iterator();
while (it.hasNext()) {
UIComponent component = (UIComponent) it.next();
@@ -81,8 +73,7 @@
}
// checks if this component has getStyle/setStyle methods
- private boolean hasStyleAttribute(UIComponent component)
- {
+ private boolean hasStyleAttribute(UIComponent component) {
Method[] methods = component.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
@@ -95,24 +86,22 @@
}
// hides component by appending 'display:none' to the 'style' attribute
- private void hideComponent(UIComponent component)
- {
+ private void hideComponent(UIComponent component) {
System.out.println("hiding component is " + component.getClass());
FacesContext context = FacesContext.getCurrentInstance();
if (!hasStyleAttribute(component)) {
- log.info("style attribute expected, not found for component "
- + component.getClientId(context));
+ Log log = getLog();
+ log.info("style attribute expected, not found for component " + component.getClientId(context));
return;
}
try {
Class c = component.getClass();
Method getStyle = c.getMethod("getStyle", new Class[] {});
- Method setStyle = c.getMethod("setStyle",
- new Class[] { String.class });
+ Method setStyle = c.getMethod("setStyle", new Class[] { String.class });
String style = (String) getStyle.invoke(component, new Object[] {});
if (style == null) {
@@ -122,30 +111,33 @@
}
setStyle.invoke(component, new Object[] { style });
} catch (Throwable e) {
- log.error("unable to set style attribute on component "
- + component.getClientId(context));
+ Log log = getLog();
+ log.error("unable to set style attribute on component " + component.getClientId(context));
}
}
+ private Log getLog() {
+ Log log = LogFactory.getLog(HtmlToggleGroupRenderer.class);
+ return log;
+ }
+
// displays component by removing, if present, any 'display:none' style
// attribute
- private void showComponent(UIComponent component)
- {
+ private void showComponent(UIComponent component) {
FacesContext context = FacesContext.getCurrentInstance();
if (!hasStyleAttribute(component)) {
- log.info("style attribute expected, not found for component "
- + component.getClientId(context));
+ Log log = getLog();
+ log.info("style attribute expected, not found for component " + component.getClientId(context));
return;
}
try {
Class c = component.getClass();
Method getStyle = c.getMethod("getStyle", new Class[] {});
- Method setStyle = c.getMethod("setStyle",
- new Class[] { String.class });
+ Method setStyle = c.getMethod("setStyle", new Class[] { String.class });
String style = (String) getStyle.invoke(component, new Object[] {});
if (style == null || style.length() == 0) {
@@ -163,27 +155,24 @@
}
setStyle.invoke(component, new Object[] { style });
} catch (Throwable e) {
- log.error("unable to set style attribute on component "
- + component.getClientId(context));
+ Log log = getLog();
+ log.error("unable to set style attribute on component " + component.getClientId(context));
}
}
// gets the edit mode from the child 'toggleOutputLink' component
- private boolean checkEditMode(List children)
- {
+ private boolean checkEditMode(List children) {
Iterator it = children.iterator();
while (it.hasNext()) {
UIComponent component = (UIComponent) it.next();
if (component instanceof ToggleOutputLink) {
- System.out.println("edit mode is "
- + ((ToggleOutputLink) component).getEditMode());
+ System.out.println("edit mode is " + ((ToggleOutputLink) component).getEditMode());
return ((ToggleOutputLink) component).getEditMode();
}
}
-
- log
- .error("Could not find child ToggleOutputLink component for HtmlToggleGroup");
+ Log log = getLog();
+ log.error("Could not find child ToggleOutputLink component for HtmlToggleGroup");
return false;
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroupTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroupTag.java?view=diff&rev=453759&r1=453758&r2=453759
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroupTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/HtmlToggleGroupTag.java Fri Oct 6 13:36:45 2006
@@ -18,15 +18,12 @@
import org.apache.myfaces.shared_tomahawk.taglib.html.HtmlPanelGroupTagBase;
-public class HtmlToggleGroupTag extends HtmlPanelGroupTagBase
-{
- public String getComponentType()
- {
+public class HtmlToggleGroupTag extends HtmlPanelGroupTagBase {
+ public String getComponentType() {
return HtmlToggleGroup.COMPONENT_TYPE;
}
- public String getRendererType()
- {
+ public String getRendererType() {
return HtmlToggleGroup.DEFAULT_RENDERER_TYPE;
}
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLink.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLink.java?view=diff&rev=453759&r1=453758&r2=453759
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLink.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLink.java Fri Oct 6 13:36:45 2006
@@ -15,15 +15,8 @@
*/
package org.apache.myfaces.custom.toggle;
-import org.apache.myfaces.custom.ajax.api.AjaxComponent;
-import org.apache.myfaces.custom.ajax.api.AjaxRenderer;
-
import javax.faces.component.html.HtmlOutputLink;
-import javax.faces.component.html.HtmlSelectOneMenu;
import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
-import javax.faces.render.Renderer;
-import java.io.IOException;
/**
* Should be nested within an HtmlToggleGroup component. Controls nested within
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLinkRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLinkRenderer.java?view=diff&rev=453759&r1=453758&r2=453759
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLinkRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLinkRenderer.java Fri Oct 6 13:36:45 2006
@@ -23,7 +23,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.renderkit.html.HtmlLinkRenderer;
+import org.apache.myfaces.renderkit.html.ext.HtmlLinkRenderer;
import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
@@ -32,107 +32,94 @@
*
* @author Sharath Reddy
*/
-public class ToggleOutputLinkRenderer extends HtmlLinkRenderer
-{
+public class ToggleOutputLinkRenderer extends HtmlLinkRenderer {
public static final int DEFAULT_MAX_SUGGESTED_ITEMS = 200;
-
-
-
- public void encodeEnd(FacesContext context, UIComponent component) throws IOException
- {
+
+ public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
RendererUtils.checkParamValidity(context, component, ToggleOutputLink.class);
super.encodeEnd(context, component);
-
+
// render the hidden input field
ResponseWriter writer = context.getResponseWriter();
- ToggleOutputLink toggleOutputLink = (ToggleOutputLink) component;
- String hiddenFieldId = toggleOutputLink.getClientId(context) +
- "_hidden";
-
+ ToggleOutputLink toggleOutputLink = (ToggleOutputLink) component;
+ String hiddenFieldId = toggleOutputLink.getClientId(context) + "_hidden";
+
writer.startElement(HTML.INPUT_ELEM, component);
writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
writer.writeAttribute(HTML.ID_ATTR, hiddenFieldId, null);
writer.writeAttribute(HTML.NAME_ATTR, hiddenFieldId, null);
-
- String value =
- new Boolean(toggleOutputLink.getEditMode()).toString();
+
+ String value = new Boolean(toggleOutputLink.getEditMode()).toString();
writer.writeAttribute(HTML.VALUE_ATTR, value, null);
-
+
writer.endElement(HTML.INPUT_ELEM);
}
-
- public void encodeBegin(FacesContext context, UIComponent component) throws IOException
- {
-
- RendererUtils.checkParamValidity(context, component, ToggleOutputLink.class);
-
- ToggleOutputLink toggleOutputLink = (ToggleOutputLink) component;
-
- this.writeJavascriptToToggleVisibility(context, toggleOutputLink);
-
- String functionName = this.getJavascriptFunctionName(context, toggleOutputLink);
- toggleOutputLink.setOnclick(functionName + "(true);");
-
- super.encodeBegin(context, component);
+
+ public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
+
+ RendererUtils.checkParamValidity(context, component, ToggleOutputLink.class);
+
+ ToggleOutputLink toggleOutputLink = (ToggleOutputLink) component;
+
+ this.writeJavascriptToToggleVisibility(context, toggleOutputLink);
+
+ String functionName = this.getJavascriptFunctionName(context, toggleOutputLink);
+ toggleOutputLink.setOnclick(functionName + "(true);");
+
+ super.encodeBegin(context, component);
}
-
- //Generate the javascript function to hide the Link component
- //and display the components specified in the 'for' attribute
- private void writeJavascriptToToggleVisibility(FacesContext context,
- ToggleOutputLink toggleOutputLink) throws IOException
- {
-
- ResponseWriter out = context.getResponseWriter();
-
- out.startElement(HTML.SCRIPT_ELEM, null);
- out.writeAttribute(HTML.TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
-
- String functionName = getJavascriptFunctionName(context, toggleOutputLink);
-
- out.write(functionName + " = function() { ");
- out.write("var toggleOutputLink = document.getElementById(");
- out.write("'" + toggleOutputLink.getClientId(context) + "'");
- out.write(");");
- out.write("\n");
- out.write("toggleOutputLink.style.display = 'none';\n");
-
- String [] componentsToToggle = toggleOutputLink.getFor().split(",");
-
- for (int i = 0; i < componentsToToggle.length; i++)
- {
- String componentId = componentsToToggle[i].trim();
-
- UIComponent component = toggleOutputLink.findComponent(componentId);
-
- if (component == null)
- {
+
+ // Generate the javascript function to hide the Link component
+ // and display the components specified in the 'for' attribute
+ private void writeJavascriptToToggleVisibility(FacesContext context, ToggleOutputLink toggleOutputLink) throws IOException {
+
+ ResponseWriter out = context.getResponseWriter();
+
+ out.startElement(HTML.SCRIPT_ELEM, null);
+ out.writeAttribute(HTML.TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
+
+ String functionName = getJavascriptFunctionName(context, toggleOutputLink);
+
+ out.write(functionName + " = function() { ");
+ out.write("var toggleOutputLink = document.getElementById(");
+ out.write("'" + toggleOutputLink.getClientId(context) + "'");
+ out.write(");");
+ out.write("\n");
+ out.write("toggleOutputLink.style.display = 'none';\n");
+
+ String[] componentsToToggle = toggleOutputLink.getFor().split(",");
+
+ for (int i = 0; i < componentsToToggle.length; i++) {
+ String componentId = componentsToToggle[i].trim();
+
+ UIComponent component = toggleOutputLink.findComponent(componentId);
+
+ if (component == null) {
Log log = LogFactory.getLog(ToggleOutputLinkRenderer.class);
- log.error("Unable to find component with id " + componentId);
- continue;
- }
-
- out.write("var component" + i + " = document.getElementById(");
- out.write("'" + component.getClientId(context) + "'");
- out.write(");\n");
- out.write("component" + i + ".style.display = 'inline';\n");
+ log.error("Unable to find component with id " + componentId);
+ continue;
+ }
+
+ out.write("var component" + i + " = document.getElementById(");
+ out.write("'" + component.getClientId(context) + "'");
+ out.write(");\n");
+ out.write("component" + i + ".style.display = 'inline';\n");
}
-
+
// toggle the value of the hidden field
- out.write("var hiddenField = document.getElementById(");
- out.write("'" + toggleOutputLink.getClientId(context) + "_hidden'");
- out.write(");\n");
- out.write("hiddenField.value = 'true';");
-
- out.write("};");
- out.endElement(HTML.SCRIPT_ELEM);
-
+ out.write("var hiddenField = document.getElementById(");
+ out.write("'" + toggleOutputLink.getClientId(context) + "_hidden'");
+ out.write(");\n");
+ out.write("hiddenField.value = 'true';");
+
+ out.write("};");
+ out.endElement(HTML.SCRIPT_ELEM);
+
}
-
- private String getJavascriptFunctionName(FacesContext context,
- ToggleOutputLink toggleOutputLink)
- {
- String modifiedId = toggleOutputLink.getClientId(context).replaceAll("\\:", "_");
- return "toggle_" + modifiedId;
+
+ private String getJavascriptFunctionName(FacesContext context, ToggleOutputLink toggleOutputLink) {
+ String modifiedId = toggleOutputLink.getClientId(context).replaceAll("\\:", "_");
+ return "toggle_" + modifiedId;
}
-
+
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLinkTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLinkTag.java?view=diff&rev=453759&r1=453758&r2=453759
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLinkTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleOutputLinkTag.java Fri Oct 6 13:36:45 2006
@@ -15,13 +15,11 @@
*/
package org.apache.myfaces.custom.toggle;
+import javax.faces.component.UIComponent;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.shared_tomahawk.taglib.html.HtmlOutputLinkTagBase;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
/**
* JSP tag class for ToggleOutputLink component