You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "CRANFORD, CHRIS" <Ch...@setech.com> on 2009/12/28 23:04:57 UTC

focusElement in s:form

I have tried all combinations of values in the focusElement tag for
s:form yet I cannot get the textfield called username to be focused when
the JSP is rendered with my login web page.  I have tried it both with
just the name of the textfield (userName) along with using the ID of the
element (login_userName) and neither have worked.

Is there anything special I could be missing here to get FF to focus on
the field when the page is rendered?



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: focusElement in s:form

Posted by Dale Newfield <da...@newfield.org>.
The only two places I found focus() called in the templates are in 
css_xhtml/form-close.ftl and xhtml/form-close.ftl.  You can look there 
to see the "magic" behind the scenes.

Also note, while you're setting the theme globally, it can also be 
changed on a tag-by-tag basis with the theme attribute.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: focusElement in s:form

Posted by Wes Wannemacher <we...@wantii.com>.
You have a few choices, you could write your own theme, but that would
be overkill for what you are trying to do... Although, I have found
that when people are using the simple theme, there is a good chance
that they are hand-rolling a theme outside of struts, which is okay,
but creating a theme is pretty easy and think of the work you'll save
later!

Other than themes, the easiest way to get to where you want would be
to simply write the Javascript yourself. Setting focus is a one-liner,
and what s:head spits out isn't particularly complex... So, just take
a look at the generated HTML and copy paste the pieces that you want.

-Wes

On Tue, Dec 29, 2009 at 9:34 AM, CRANFORD, CHRIS
<Ch...@setech.com> wrote:
> It appears if I removed this line and additionally made sure that the
> <s:head/> tag was inside my HTML <head>...</head> block that the
> appropriate logic works and the StrutsUtil class is available and
> focuses on my elements.
>
> Now is there a way to avoid this extra <td class='tdLabel'></td> from
> being decorated on my input fields?  I suppose this is part of the
> standard theme and sometimes the labels for my fields have to be
> positioned in certain ways, not sure I want to use this particular
> theme, ugh.
>
>
>
> -----Original Message-----
> From: CRANFORD, CHRIS [mailto:Chris.Cranford@setech.com]
> Sent: Tuesday, December 29, 2009 8:15 AM
> To: Struts Users Mailing List
> Subject: RE: focusElement in s:form
>
> I do have in my struts.xml file the following defined:
>
>  <constant name="struts.ui.theme" value="simple"/>
>
> Does this affect this?
>
> -----Original Message-----
> From: Dale Newfield [mailto:dale@newfield.org]
> Sent: Monday, December 28, 2009 4:56 PM
> To: Struts Users Mailing List
> Subject: Re: focusElement in s:form
>
> CRANFORD, CHRIS wrote:
>> I don't see any Javascript code in the Source file in the browser at
>> all.  That's what is not making any sense to me for the form tag.  It
> is
>> as if the focusElement doesn't cause the <s:form> tag to do anything
> at
>> all.
>>
>> I would expect to see some <script> .... </script> stuff in the source
>> file that is rendered, correct?
>
> Yes.  Are you using a specific theme for your s: tags?
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: focusElement in s:form

Posted by "CRANFORD, CHRIS" <Ch...@setech.com>.
It appears if I removed this line and additionally made sure that the
<s:head/> tag was inside my HTML <head>...</head> block that the
appropriate logic works and the StrutsUtil class is available and
focuses on my elements.  

Now is there a way to avoid this extra <td class='tdLabel'></td> from
being decorated on my input fields?  I suppose this is part of the
standard theme and sometimes the labels for my fields have to be
positioned in certain ways, not sure I want to use this particular
theme, ugh.



-----Original Message-----
From: CRANFORD, CHRIS [mailto:Chris.Cranford@setech.com] 
Sent: Tuesday, December 29, 2009 8:15 AM
To: Struts Users Mailing List
Subject: RE: focusElement in s:form

I do have in my struts.xml file the following defined:

  <constant name="struts.ui.theme" value="simple"/>

Does this affect this?  

-----Original Message-----
From: Dale Newfield [mailto:dale@newfield.org] 
Sent: Monday, December 28, 2009 4:56 PM
To: Struts Users Mailing List
Subject: Re: focusElement in s:form

CRANFORD, CHRIS wrote:
> I don't see any Javascript code in the Source file in the browser at
> all.  That's what is not making any sense to me for the form tag.  It
is
> as if the focusElement doesn't cause the <s:form> tag to do anything
at
> all.
> 
> I would expect to see some <script> .... </script> stuff in the source
> file that is rendered, correct?

Yes.  Are you using a specific theme for your s: tags?

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: focusElement in s:form

Posted by "CRANFORD, CHRIS" <Ch...@setech.com>.
I do have in my struts.xml file the following defined:

  <constant name="struts.ui.theme" value="simple"/>

Does this affect this?  

-----Original Message-----
From: Dale Newfield [mailto:dale@newfield.org] 
Sent: Monday, December 28, 2009 4:56 PM
To: Struts Users Mailing List
Subject: Re: focusElement in s:form

CRANFORD, CHRIS wrote:
> I don't see any Javascript code in the Source file in the browser at
> all.  That's what is not making any sense to me for the form tag.  It
is
> as if the focusElement doesn't cause the <s:form> tag to do anything
at
> all.
> 
> I would expect to see some <script> .... </script> stuff in the source
> file that is rendered, correct?

Yes.  Are you using a specific theme for your s: tags?

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: focusElement in s:form

Posted by Dale Newfield <da...@newfield.org>.
CRANFORD, CHRIS wrote:
> I don't see any Javascript code in the Source file in the browser at
> all.  That's what is not making any sense to me for the form tag.  It is
> as if the focusElement doesn't cause the <s:form> tag to do anything at
> all.
> 
> I would expect to see some <script> .... </script> stuff in the source
> file that is rendered, correct?

Yes.  Are you using a specific theme for your s: tags?

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: focusElement in s:form

Posted by "CRANFORD, CHRIS" <Ch...@setech.com>.
I don't see any Javascript code in the Source file in the browser at
all.  That's what is not making any sense to me for the form tag.  It is
as if the focusElement doesn't cause the <s:form> tag to do anything at
all.

I would expect to see some <script> .... </script> stuff in the source
file that is rendered, correct?


-----Original Message-----
From: Dale Newfield [mailto:dale@newfield.org] 
Sent: Monday, December 28, 2009 4:38 PM
To: Struts Users Mailing List
Subject: Re: focusElement in s:form

CRANFORD, CHRIS wrote:
> I have removed all javascript from the JSP page and installed Firebug.
> No errors show up and Javascript is enabled.  I get the same result in
> IE as well where my form isn't focusing on my userName field.

So put a breakpoint on the javascript line that is making the focus() 
call, and make sure it's getting executed and doing what it should.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: focusElement in s:form

Posted by Dale Newfield <da...@newfield.org>.
CRANFORD, CHRIS wrote:
> I have removed all javascript from the JSP page and installed Firebug.
> No errors show up and Javascript is enabled.  I get the same result in
> IE as well where my form isn't focusing on my userName field.

So put a breakpoint on the javascript line that is making the focus() 
call, and make sure it's getting executed and doing what it should.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: focusElement in s:form

Posted by "CRANFORD, CHRIS" <Ch...@setech.com>.
I have removed all javascript from the JSP page and installed Firebug.
No errors show up and Javascript is enabled.  I get the same result in
IE as well where my form isn't focusing on my userName field.

Wonder what else it could be.

-----Original Message-----
From: Dale Newfield [mailto:dale@newfield.org] 
Sent: Monday, December 28, 2009 4:10 PM
To: Struts Users Mailing List
Subject: Re: focusElement in s:form

CRANFORD, CHRIS wrote:
> Is there anything special I could be missing here to get FF to focus
on
> the field when the page is rendered?

There's no magic.  The only way for this to happen is by executing a 
snippet of javascript in the browser.  Therefore this will not work in a

browser that has javascript turned off, or on a page that has javascript

errors.  I'd recommend using the "FireBug" plugin for FF and looking at 
the console to see what's happening.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: focusElement in s:form

Posted by Dale Newfield <da...@newfield.org>.
CRANFORD, CHRIS wrote:
> Is there anything special I could be missing here to get FF to focus on
> the field when the page is rendered?

There's no magic.  The only way for this to happen is by executing a 
snippet of javascript in the browser.  Therefore this will not work in a 
browser that has javascript turned off, or on a page that has javascript 
errors.  I'd recommend using the "FireBug" plugin for FF and looking at 
the console to see what's happening.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org