You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ca...@apache.org on 2008/08/21 10:25:00 UTC
svn commit: r687641 - in /myfaces/tomahawk/trunk/sandbox/core/src/main:
java/org/apache/myfaces/custom/toggle/
resources/org/apache/myfaces/custom/toggle/
resources/org/apache/myfaces/custom/toggle/resource/
Author: cagatay
Date: Thu Aug 21 01:24:59 2008
New Revision: 687641
URL: http://svn.apache.org/viewvc?rev=687641&view=rev
Log:
Fix for TOMAHAWK-1315, focus the untoggled component when the toggleLink is clicked automatically, also added onClickFocusId attribute to specify the component manually
Added:
myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/toggle/
myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/toggle/resource/
myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/toggle/resource/scrollTo.js (with props)
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/AbstractToggleLink.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleLinkRenderer.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/TogglePanelRenderer.java
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/AbstractToggleLink.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/AbstractToggleLink.java?rev=687641&r1=687640&r2=687641&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/AbstractToggleLink.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/AbstractToggleLink.java Thu Aug 21 01:24:59 2008
@@ -67,6 +67,15 @@
*/
public abstract boolean isDisabled();
+ /**
+ * Id of the component that will be focused when toggleLink is clicked
+ *
+ * @JSFProperty
+ * literalOnly = "true"
+ * @return
+ */
+ public abstract String getOnClickFocusId();
+
public AbstractToggleLink()
{
super();
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleLinkRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleLinkRenderer.java?rev=687641&r1=687640&r2=687641&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleLinkRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleLinkRenderer.java Thu Aug 21 01:24:59 2008
@@ -58,48 +58,14 @@
if (UserRoleUtils.isEnabledOnUserRole(output))
{
ResponseWriter writer = facesContext.getResponseWriter();
-
- //calculate href
- String href = org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils
- .getStringValue(facesContext, output);
-
- if (href == null)
- {
- href = "";
- }
- if ("".equals(href) || "#".equals(href))
- {
- //If no value defined the default is #componentId where
- //componentId is the clientId of the component to be
- //shown. This avoid that the page jumps to top on every click.
- ToggleLink toggleLink = (ToggleLink) output;
- String[] componentsToToggle = toggleLink.getFor().split(",");
- for (int i = 0; i < componentsToToggle.length; i++) {
- String componentId = componentsToToggle[i].trim();
- UIComponent componentToShow = toggleLink.findComponent(componentId);
- if (componentToShow != null){
- href = "#"+ componentToShow.getClientId(facesContext);
- break;
- }
- }
- }
- if (getChildCount(output) > 0)
- {
- StringBuffer hrefBuf = new StringBuffer(href);
- addChildParametersToHref(facesContext, output, hrefBuf, (href
- .indexOf('?') == -1), //first url parameter?
- writer.getCharacterEncoding());
- href = hrefBuf.toString();
- }
- href = facesContext.getExternalContext().encodeResourceURL(href); //TODO: or encodeActionURL ?
-
+
String clientId = output.getClientId(facesContext);
//write anchor
writer.startElement(HTML.ANCHOR_ELEM, output);
writer.writeAttribute(HTML.ID_ATTR, clientId, null);
writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
- writer.writeURIAttribute(HTML.HREF_ATTR, href, null);
+ writer.writeURIAttribute(HTML.HREF_ATTR, "javascript:void(0);", null);
HtmlRendererUtils
.renderHTMLAttributes(
@@ -111,9 +77,9 @@
HtmlRendererUtils.renderHTMLAttribute(writer, HTML.STYLE_CLASS_ATTR, HTML.STYLE_CLASS_ATTR,
output.getAttributes().get(HTML.STYLE_CLASS_ATTR));
- HtmlRendererUtils.renderHTMLAttribute(writer, HTML.ONCLICK_ATTR, HTML.ONCLICK_ATTR,
+ HtmlRendererUtils.renderHTMLAttribute(writer, HTML.ONCLICK_ATTR, HTML.ONCLICK_ATTR,
buildOnclickToggleFunction(facesContext,output));
-
+
writer.flush();
}
}
@@ -140,6 +106,16 @@
String outputOnclick = toggleLink.getOnclick();
StringBuffer onClick = new StringBuffer();
+ if(toggleLink.getOnClickFocusId() != null)
+ {
+ String onClickFocusClientId = toggleLink.findComponent(toggleLink.getOnClickFocusId()).getClientId(facesContext);
+ onClick.append(getToggleJavascriptFunctionName(facesContext, toggleLink) + "('"+idsToShow+"','" + onClickFocusClientId + "');");
+ }
+ else
+ {
+ onClick.append(getToggleJavascriptFunctionName(facesContext, toggleLink) + "('"+idsToShow+"','');");
+ }
+
if (outputOnclick != null)
{
onClick.append("var cf = function(){");
@@ -149,8 +125,6 @@
onClick.append("var oamSF = function(){");
}
- onClick.append(getToggleJavascriptFunctionName(facesContext, toggleLink) + "('"+idsToShow+"')");
-
if (outputOnclick != null)
{
onClick.append('}');
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/TogglePanelRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/TogglePanelRenderer.java?rev=687641&r1=687640&r2=687641&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/TogglePanelRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/TogglePanelRenderer.java Thu Aug 21 01:24:59 2008
@@ -29,6 +29,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.renderkit.html.util.AddResource;
+import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlGroupRendererBase;
@@ -45,6 +47,8 @@
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
RendererUtils.checkParamValidity(context, component, TogglePanel.class);
+ addScrollToJavascript(context);
+
TogglePanel togglePanel = (TogglePanel) component;
boolean toggleMode = togglePanel.isToggled();
toggleVisibility(togglePanel.getChildren(), toggleMode);
@@ -156,7 +160,7 @@
String functionName = getToggleJavascriptFunctionName(context, togglePanel);
- out.write("function "+functionName + "(idsToShowS){\n");
+ out.write("function "+functionName + "(idsToShowS,onClickFocusId){\n");
StringBuffer idsToHide = new StringBuffer();
int idsToHideCount = 0;
@@ -179,8 +183,10 @@
getLog().warn( "TogglePanel "+ togglePanel.getClientId(context) +" has no visible components when toggled." );
}
out.write( "var idsToShow = idsToShowS.split(',');\n" );
- out.write( "for(var j=0;j<idsToShow.length;j++) document.getElementById(idsToShow[j]).style.display = 'inline';\n");
-
+ out.write( "scrollTo(idsToShow[0]);\n" );
+ out.write( "for(var j=0;j<idsToShow.length;j++) {document.getElementById(idsToShow[j]).style.display = 'inline';}\n");
+ out.write( "if(onClickFocusId != '') document.getElementById(onClickFocusId).focus();\n");
+ out.write( "else document.getElementById(idsToShow[0]).focus();\n");
// toggle the value of the hidden field
out.write("document.getElementById('" + getHiddenFieldId(context, togglePanel) + "').value = '1';\n");
@@ -192,4 +198,10 @@
String modifiedId = togglePanel.getClientId(context).replaceAll("\\:", "_").replaceAll("-", "_");
return "toggle_" + modifiedId;
}
+
+ public void addScrollToJavascript(FacesContext context)throws IOException {
+ AddResource addResource = AddResourceFactory.getInstance(context);
+
+ addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, AbstractTogglePanel.class, "scrollTo.js");
+ }
}
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/toggle/resource/scrollTo.js
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/toggle/resource/scrollTo.js?rev=687641&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/toggle/resource/scrollTo.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/toggle/resource/scrollTo.js Thu Aug 21 01:24:59 2008
@@ -0,0 +1,6 @@
+function scrollTo(id){
+ var theelement = document.getElementById(id);
+ if(theelement.scrollIntoView){
+ theelement.scrollIntoView(true);
+ }
+}
\ No newline at end of file
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/toggle/resource/scrollTo.js
------------------------------------------------------------------------------
svn:eol-style = native