Thanks to Jason and Ryan for the comments. I've incorporated all
comments (final strings, value expressions, and renderer) except the
facelets tag descriptor - (I haven't worked with facelets before, and
would like to put this back soon, rather than take a couple days to
learn facelets. Hope that's ok. I need to also add facelet tags for
the two validators I've written as well.)
This is currently into the mojarra_ext library, but on further
reflection, I think Jason is right and we should probably just put it
into the sandbox. I'd like to have that discussion in a separate
thread, since that means refactoring the work I've already put back. If
that's a blocker, let me know.
This is the tag that we were talking about on the list. This is the
simple version, you just use <mj:focus for="componetID"/>.
I'd still like to see it as an attribute on f:view for 2.0. I've filed
that as spec issue 354.
SECTION: Modified Files
----------------------------
M jsf-ri/conf/share/mojarra_ext.tld
M jsf-ri/src/com/sun/faces/jsf-ri-config.xml
- Config changes to add focus tag. "for" attribute is required.
A jsf-ri/src/com/sun/faces/ext/render/FocusHTMLRenderer.java
A jsf-ri/src/com/sun/faces/ext/component/UIFocus.java
- Component and associated renderer for focus tag.
A jsf-ri/src/com/sun/faces/ext/taglib/FocusTag.java
- Tag class for new Focus component.
M jsf-demo/mojarra_ext/web/landing.jsp
M jsf-demo/mojarra_ext/web/welcome.jsp
- Update demo to use new focus tag.
SECTION: Diffs
----------------------------
Index: jsf-demo/mojarra_ext/web/landing.jsp
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-demo/mojarra_ext/web/landing.jsp,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 landing.jsp
--- jsf-demo/mojarra_ext/web/landing.jsp 7 Apr 2008 17:55:23 -0000 1.1.2.2
+++ jsf-demo/mojarra_ext/web/landing.jsp 9 Apr 2008 00:30:19 -0000
@@ -61,6 +61,7 @@
<h:message id="creditcardError" for="sampleCreditCard"/>
<br/>
<h:commandButton id="submit" action="back" value="Back" />
+ <mj:focus for="sampleCreditCard"/>
</h:form>
</f:view>
Index: jsf-demo/mojarra_ext/web/welcome.jsp
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-demo/mojarra_ext/web/welcome.jsp,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 welcome.jsp
--- jsf-demo/mojarra_ext/web/welcome.jsp 7 Apr 2008 17:55:23 -0000 1.1.2.2
+++ jsf-demo/mojarra_ext/web/welcome.jsp 9 Apr 2008 00:30:19 -0000
@@ -61,6 +61,7 @@
</h:inputText>
<h:message id="regexError" for="sampleRegex"
showDetail="true" showSummary="false"/><br/>
<h:commandButton id="submit" action="landing"
value="Go" />
+ <mj:focus for="sampleRegex"/>
</h:form>
</f:view>
</body>
Index: jsf-ri/conf/share/mojarra_ext.tld
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/conf/share/mojarra_ext.tld,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 mojarra_ext.tld
--- jsf-ri/conf/share/mojarra_ext.tld 7 Apr 2008 17:55:23 -0000 1.1.2.2
+++ jsf-ri/conf/share/mojarra_ext.tld 9 Apr 2008 00:30:19 -0000
@@ -39,7 +39,8 @@
<taglib version="2.0" xmlns="
http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/j2ee
web-jsptaglibrary_2_0.xsd">
- <tlib-version>1.0</tlib-version>
+ <tlib-version>1.1</tlib-version>
+ <jsp-version>2.1</jsp-version>
<short-name>mj</short-name>
<uri>
http://mojarra.dev.java.net/mojarra_ext</uri>
<tag>
@@ -75,4 +76,33 @@
<tag-class>com.sun.faces.ext.taglib.CreditCardValidatorTag</tag-class>
<body-content>empty</body-content>
</tag>
+ <tag>
+ <name>focus</name>
+ <description>
+ A tag to set the focus on a specified field. Place it
within a form
+ tag, and set the for attribute to point to the field that
should receive
+ the focus.
+ </description>
+ <tag-class>com.sun.faces.ext.taglib.FocusTag</tag-class>
+ <attribute>
+ <name>binding</name>
+ <description>A value binding that points to a bean
property</description>
+ </attribute>
+ <attribute>
+ <name>id</name>
+ <description>The client id of this component</description>
+ </attribute>
+ <attribute>
+ <name>rendered</name>
+ <description>Is this component rendered?</description>
+ </attribute>
+ <attribute>
+ <name>for</name>
+ <description>component ID that should receive the
focus</description>
+ <deferred-value>
+ <type>java.lang.String</type>
+ </deferred-value>
+ <required>true</required>
+ </attribute>
+ </tag>
</taglib>
Index: jsf-ri/src/com/sun/faces/jsf-ri-config.xml
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/jsf-ri-config.xml,v
retrieving revision 1.73.4.2
diff -u -r1.73.4.2 jsf-ri-config.xml
--- jsf-ri/src/com/sun/faces/jsf-ri-config.xml 7 Apr 2008 17:55:22
-0000 1.73.4.2
+++ jsf-ri/src/com/sun/faces/jsf-ri-config.xml 9 Apr 2008 00:30:19 -0000
@@ -211,4 +211,18 @@
<validator-class>com.sun.faces.ext.validator.CreditCardValidator</validator-class>
</validator>
+ <!-- Add our implementation specific Components -->
+ <component>
+ <component-type>com.sun.faces.ext.focus</component-type>
+
<component-class>com.sun.faces.ext.component.UIFocus</component-class>
+ </component>
+
+ <!-- Add our implementation specific Renderers -->
+ <render-kit>
+ <renderer>
+ <component-family>FocusFamily</component-family>
+
<renderer-type>com.sun.faces.ext.render.FocusHTMLRenderer</renderer-type>
+
<renderer-class>com.sun.faces.ext.render.FocusHTMLRenderer</renderer-class>
+ </renderer>
+ </render-kit>
</faces-config>
SECTION: New Files
----------------------------
SEE ATTACHMENTS