You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2009/06/21 13:30:32 UTC
svn commit: r786993 - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/taglib/decl/
theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/
theme/standard/src/main/java/org/apache/myfaces...
Author: bommel
Date: Sun Jun 21 11:30:31 2009
New Revision: 786993
URL: http://svn.apache.org/viewvc?rev=786993&view=rev
Log:
(TOBAGO-768) The first input component with an error should get the default focus
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/IsFocus.java
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/DateRenderer.java
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TextAreaRenderer.java
myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtil.java
myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/IsFocus.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/IsFocus.java?rev=786993&r1=786992&r2=786993&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/IsFocus.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/IsFocus.java Sun Jun 21 11:30:31 2009
@@ -22,7 +22,6 @@
/*
* Created: Apr 9, 2005 3:16:44 PM
- * User: bommel
* $Id$
*/
public interface IsFocus {
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/DateRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/DateRenderer.java?rev=786993&r1=786992&r2=786993&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/DateRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/DateRenderer.java Sun Jun 21 11:30:31 2009
@@ -82,10 +82,6 @@
+ "DatePicker may not work correctly.");
}
}
-
- // focus
- // TODO is this not already done in InRenderer?
- HtmlRendererUtil.renderFocusId(facesContext, component);
}
}
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TextAreaRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TextAreaRenderer.java?rev=786993&r1=786992&r2=786993&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TextAreaRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TextAreaRenderer.java Sun Jun 21 11:30:31 2009
@@ -130,7 +130,8 @@
}
// focus
- HtmlRendererUtil.renderFocusId(facesContext, component);
+ HtmlRendererUtil.renderFocusId(facesContext, input);
+
}
}
Modified: myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtil.java?rev=786993&r1=786992&r2=786993&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtil.java (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtil.java Sun Jun 21 11:30:31 2009
@@ -67,14 +67,39 @@
public final class HtmlRendererUtil {
private static final Log LOG = LogFactory.getLog(HtmlRendererUtil.class);
+ private static final String ERROR_FOCUS_KEY = HtmlRendererUtil.class.getName() + ".ErrorFocusId";
private HtmlRendererUtil() {
// to prevent instantiation
}
- public static void renderFocusId(FacesContext facesContext, UIComponent component)
+ private static boolean renderErrorFocusId(final FacesContext facesContext, final UIInput input) throws IOException {
+ if (ComponentUtil.isError(input)) {
+ if (!FacesContext.getCurrentInstance().getExternalContext().getRequestMap().containsKey(ERROR_FOCUS_KEY)) {
+ FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put(ERROR_FOCUS_KEY, Boolean.TRUE);
+ TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
+ String id = input.getClientId(facesContext);
+ writer.writeJavascript("Tobago.errorFocusId = '" + id + "';");
+ return true;
+ } else {
+ return true;
+ }
+ }
+ return FacesContext.getCurrentInstance().getExternalContext().getRequestMap().containsKey(ERROR_FOCUS_KEY);
+ }
+
+ public static void renderFocusId(final FacesContext facesContext, final UIComponent component)
throws IOException {
+ if (component instanceof UIInput) {
+ renderFocusId(facesContext, (UIInput) component);
+ }
+ }
+ public static void renderFocusId(final FacesContext facesContext, final UIInput component)
+ throws IOException {
+ if (renderErrorFocusId(facesContext, component)) {
+ return;
+ }
if (ComponentUtil.getBooleanAttribute(component, Attributes.FOCUS)) {
UIPage page = (UIPage) ComponentUtil.findPage(facesContext, component);
String id = component.getClientId(facesContext);
Modified: myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=786993&r1=786992&r2=786993&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Sun Jun 21 11:30:31 2009
@@ -113,6 +113,8 @@
*/
focusId: undefined,
+ errorFocusId:undefined,
+
htmlIdIndex: 0,
createHtmlId: function() {
@@ -1197,7 +1199,7 @@
* no element is explicitly requested.
*/
setFocus: function() {
- var focusElement = this.element(this.focusId);
+ var focusElement = this.element(this.errorFocusId == "undefined" ? this.focusId: this.errorFocusId);
if (focusElement) {
try { // focus() on not visible elements breaks IE
focusElement.focus();