You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by ml...@apache.org on 2011/08/13 13:58:43 UTC
svn commit: r1157371 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/corelib/mixins/ test/app1/
test/groovy/org/apache/tapestry5/integration/app1/
test/java/org/apache/tapestry5/integration/app1/pages/
Author: mlusetti
Date: Sat Aug 13 11:58:43 2011
New Revision: 1157371
URL: http://svn.apache.org/viewvc?rev=1157371&view=rev
Log:
TAP5-650 Enhance form autofocus to accept fieldname as a value
Actually a new mixin is used to bind to the Field from the Form which will receive the focus
The most difficult part was to find a reliable way for Selenium to get the current focused HTML element
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/FormFieldFocus.java (with props)
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFieldFocusDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/FormFieldFocusTest.groovy
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldFocusDemo.java (with props)
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/FormFieldFocus.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/FormFieldFocus.java?rev=1157371&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/FormFieldFocus.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/FormFieldFocus.java Sat Aug 13 11:58:43 2011
@@ -0,0 +1,69 @@
+// Copyright (c) 2011. 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.tapestry5.corelib.mixins;
+
+import org.apache.tapestry5.BindingConstants;
+import org.apache.tapestry5.ClientElement;
+import org.apache.tapestry5.Field;
+import org.apache.tapestry5.FieldFocusPriority;
+import org.apache.tapestry5.annotations.AfterRender;
+import org.apache.tapestry5.annotations.Environmental;
+import org.apache.tapestry5.annotations.InjectContainer;
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.corelib.components.Form;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.javascript.JavaScriptSupport;
+import org.slf4j.Logger;
+
+/**
+ * A mixin that instruments the outer {@link org.apache.tapestry5.corelib.components.Form} on which
+ * component the focus should be activated.
+ * <p/>
+ * This is meant to be used only with {@link org.apache.tapestry5.corelib.components.Form} component.
+ *
+ * @since 5.3
+ * @tapestrydoc
+ */
+public class FormFieldFocus
+{
+ @Inject
+ private Logger logger;
+
+ /**
+ * The outer Form
+ */
+ @InjectContainer
+ private Form form;
+
+ /**
+ * The {@link org.apache.tapestry5.Field} instance that will receive the focus within
+ * the {@link org.apache.tapestry5.corelib.components.Form}.
+ */
+ @Parameter(required = true, defaultPrefix = BindingConstants.COMPONENT, allowNull = false)
+ private Field focusField;
+
+ @Environmental
+ private JavaScriptSupport javascriptSupport;
+
+
+ @AfterRender
+ void focusField()
+ {
+ javascriptSupport.autofocus(FieldFocusPriority.OVERRIDE, focusField.getControlName());
+
+ logger.trace("Focus OVERRIDE done on field {}", focusField.getControlName());
+ }
+
+}
Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/FormFieldFocus.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFieldFocusDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFieldFocusDemo.tml?rev=1157371&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFieldFocusDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFieldFocusDemo.tml Sat Aug 13 11:58:43 2011
@@ -0,0 +1,14 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" xml:space="default">
+ <h1>Form Focus Field Demo</h1>
+
+ <t:form t:id="focusform" name="focusform" t:mixins="formfieldfocus" t:focusfield="gainFocus">
+
+ <t:label for="requiredValue" />
+ <t:textfield t:id="requiredValue" t:validate="required"/>
+ <br/>
+ <t:label for="gainFocus" />
+ <t:textfield t:id="gainFocus" t:value="gainFocusValue" />
+
+ </t:form>
+
+</html>
\ No newline at end of file
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/FormFieldFocusTest.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/FormFieldFocusTest.groovy?rev=1157371&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/FormFieldFocusTest.groovy (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/FormFieldFocusTest.groovy Sat Aug 13 11:58:43 2011
@@ -0,0 +1,34 @@
+// Copyright (c) 2011. 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.tapestry5.integration.app1
+
+import org.apache.tapestry5.integration.TapestryCoreTestCase
+import org.testng.annotations.Test
+
+/**
+ * Integration test to veryfiy {@link FormFieldFocusTest} mixin.
+ */
+class FormFieldFocusTest extends TapestryCoreTestCase
+{
+ @Test
+ void form_field_focus_mixin()
+ {
+ openLinks "FormFieldFocus Demo"
+
+ assertEquals getEval("window.document.activeElement.value"), "But I got the focus!"
+
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldFocusDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldFocusDemo.java?rev=1157371&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldFocusDemo.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldFocusDemo.java Sat Aug 13 11:58:43 2011
@@ -0,0 +1,40 @@
+// Copyright (c) 2011. 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.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.Field;
+import org.apache.tapestry5.annotations.InjectComponent;
+import org.apache.tapestry5.annotations.Property;
+
+public class FormFieldFocusDemo
+{
+ @InjectComponent @Property
+ private Field gainFocus;
+
+ @Property
+ private String requiredValue;
+
+ @Property
+ private String gainFocusValue;
+
+
+ void beginRender()
+ {
+ requiredValue = "I'm required";
+
+ gainFocusValue = "But I got the focus!";
+ }
+
+}
Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldFocusDemo.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java?rev=1157371&r1=1157370&r2=1157371&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java Sat Aug 13 11:58:43 2011
@@ -491,7 +491,9 @@ public class Index
new Item("NestedFormFragment", "Nested Form Fragment Demo", "Nesting Form Fragments work properly"),
- new Item("MapExpressionInExpansions", "Map Expressions in Expansions Demo", "Maps can be used in expansions")
+ new Item("MapExpressionInExpansions", "Map Expressions in Expansions Demo", "Maps can be used in expansions"),
+
+ new Item("FormFieldFocusDemo", "FormFieldFocus Demo", "Setting the Form focus on a specific field")
);