struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Denis Cabasson <denis.cabas...@gmail.com>
Subject Re: how to set default focus field in <s:form> ?
Date Thu, 13 May 2010 02:53:44 GMT
I recommend attaching the focus to the relevant form element purely 
using Javascript,

ie, including in you JSP :
<script type="test/javascript">
window.onload = function() {
     document.getElementById('yourInpudId').focus();
}
</script>

That way you have a pure javascript implementation, and you can push 
that code to the relevant JSP without having to mess up with your template.

My second recommendation is to use a Javascript framework, instead of 
the plain and ugly javascript as up there (since the example above will 
break if you want to attach more than one thing to the onload).
So rewritten with jquery ( http://jquery.com/ )
<script type="test/javascript">
$(document).ready(function() {
   $('yourInpudId').focus();
});
</script>

But the idea is the same in both case, do the focus purely in Javascript.

Denis.

Le 2010-05-12 14:53, Emi Lu a écrit :
>
>>> By using tiles,<body>  is in global_layout.jsp page, for decedent 
>>> pages,
>>> I will not be able to set body onload.
>>>
>>
>> Admittedly I don't know tiles, but Sitemesh will copy the body onLoad 
>> and
>> unload functions to the decorating page and I would be suprised if Tiles
>> didn't support this as well.
>
> For the global page.jsp: if body onload is set, it's for all 
> decedents; no, I do not want that.
>
> (1) Do not bother to create several parents layout files
> (2) Only one file needs default focus;
>     Other hundreds of .jsp foucs will be set differently or
>     not set at all
>
> So, I do need s:form to support focus.
>
> -- 
> Lu Ying
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message