You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mario Ivankovits <ma...@ops.co.at> on 2006/01/15 09:12:41 UTC

keep resulting html small (was: Re: commandLink)

Hi!
> <a href="#"
> onclick="clear__5Fid0();document.forms['_id0'].elements['autoScroll'].value=
> getScrolling();document.forms['_id0'].elements['_id0:_link_hidden_'].value='
> _id0:pageID';if(document.forms['_id0'].onsubmit){if(document.forms['_id0'].o
> nsubmit())
> document.forms['_id0'].submit();}else{document.forms['_id0'].submit();}retur
> n false;" id="_id0:pageID"></a
>   
One thing which makes me felling a little bit uncomfortable is the size
of the resulting html file.
Say you have hundreds of command links in your jsf
(tree/datatable/navigation) especially a tree with client side
navigation tends to hold many entries - imagine the size of the
resulting html file with all this onclick= on each command link.

Like the clear__ method we can render a submit__ javascript method which
wraps all this stuff, cant we?

And maybe we can call this clear__ from within submit__ too, so this
makes the above url something like:

> <a href="#"
> onclick="return submit__5Fid0()" id="_id0:pageID"></a
>   
Or do I miss something?
If not, I'll prepare a patch for it.

Ciao,
Mario


Re: keep resulting html small

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
> The function definition should be "inline" in the page rather than a
> reference to an external resource file. 
>
> Isn't it possible to simply emit the script when first needed, and put a
> boolean flag somewhere to indicate that the script has been output so
> later command components don't duplicate it?
>   
OK, so I'll do it that way.

Ciao,
Mario


Re: keep resulting html small

Posted by Simon Kitching <sk...@apache.org>.
On Sun, 2006-01-15 at 11:41 +0100, Mario Ivankovits wrote:
> Simon Kitching wrote:
> > Rather than "return submit__5Fid0()", I'd like to see:
> >   onclick="return myfaces_submit(this)"
> > where the myfaces_submit function gets defined only once.
> >
> > Is there any reason not to do this?
> >   
> The only thing which comes in my mind is that we then have to require
> the facesExtension filter setup correctly. We need to render this
> myfaces_submit only once!
> 
> Is it an option that non-myfaces extensions require this filter? If not,
> I'll go the _id way for now.

No, implementing this via the extensions filter was not what I meant.
That's clearly not acceptable for something in myfaces-core.

The function definition should be "inline" in the page rather than a
reference to an external resource file. It doesn't need to be in the
<head> section of the page. It should be before any event handler that
references it, as the user can click on the command component as soon as
it has rendered on their screen (even if the rest of the page is still
downloading).

Isn't it possible to simply emit the script when first needed, and put a
boolean flag somewhere to indicate that the script has been output so
later command components don't duplicate it?

eg:
  encodeEnd() {
    SubmitUtils.generateSubmitFunction();
    responseWriter.startElement("button");
    responseWriter.addAttribute("onclick", "myfaces_submit(this)");
  }

where
  SubmitUtils.generateSubmitFunction does:
    if (request.get(SUBMIT_UTILS_KEY) != null)
      return;
    responseWriter.startElement("script");
    .....
    request.put(SUBMIT_UTILS_KEY, Boolean.TRUE);

The DummyFormUtils class does similar functionality; it generates just a
single dummy form for the current page. However it uses some rather
sneaky tricks to achieve this which I'm not fond of. And it does have
some requirements that the script thingy doesn't; in particular a
<script> can be emitted just about anywhere, while DummyUtils can't
render the dummy form while inside some other <form> tag. So the first
approach suggested above would be my preferred implementation unless
there's something I've missed.

Cheers,

Simon



Re: keep resulting html small

Posted by Mario Ivankovits <ma...@ops.co.at>.
Simon Kitching wrote:
> Rather than "return submit__5Fid0()", I'd like to see:
>   onclick="return myfaces_submit(this)"
> where the myfaces_submit function gets defined only once.
>
> Is there any reason not to do this?
>   
The only thing which comes in my mind is that we then have to require
the facesExtension filter setup correctly. We need to render this
myfaces_submit only once!

Is it an option that non-myfaces extensions require this filter? If not,
I'll go the _id way for now.

Ciao,
Mario


Re: keep resulting html small (was: Re: commandLink)

Posted by Martin Marinschek <ma...@gmail.com>.
absolutely +1 here.

regards,

Martin

On 1/15/06, Simon Kitching <sk...@apache.org> wrote:
> On Sun, 2006-01-15 at 09:12 +0100, Mario Ivankovits wrote:
> > Hi!
> > > <a href="#"
> > > onclick="clear__5Fid0();document.forms['_id0'].elements['autoScroll'].value=
> > > getScrolling();document.forms['_id0'].elements['_id0:_link_hidden_'].value='
> > > _id0:pageID';if(document.forms['_id0'].onsubmit){if(document.forms['_id0'].o
> > > nsubmit())
> > > document.forms['_id0'].submit();}else{document.forms['_id0'].submit();}retur
> > > n false;" id="_id0:pageID"></a
> > >
> > One thing which makes me felling a little bit uncomfortable is the size
> > of the resulting html file.
> > Say you have hundreds of command links in your jsf
> > (tree/datatable/navigation) especially a tree with client side
> > navigation tends to hold many entries - imagine the size of the
> > resulting html file with all this onclick= on each command link.
> >
> > Like the clear__ method we can render a submit__ javascript method which
> > wraps all this stuff, cant we?
> >
> > And maybe we can call this clear__ from within submit__ too, so this
> > makes the above url something like:
> >
> > > <a href="#"
> > > onclick="return submit__5Fid0()" id="_id0:pageID"></a
> > >
> > Or do I miss something?
> > If not, I'll prepare a patch for it.
>
> I'd really like to see this. It's been on my to-do list for a while.
> When a page has a large table containing a commandLink, the resulting
> html is currently *much* larger than it needs to be.
>
> Rather than "return submit__5Fid0()", I'd like to see:
>   onclick="return myfaces_submit(this)"
> where the myfaces_submit function gets defined only once.
>
> Is there any reason not to do this?
>
> Note that there has recently been some discussion about "namespacing"
> javascript methods. However moving to at least *having* a single
> function definition is a good first step, even if "myfaces_submit" isn't
> the final way to access that function.
>
> Cheers,
>
> Simon
>
>


--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

RE: keep resulting html small (was: Re: commandLink)

Posted by Yee CN <ye...@streamyx.com>.
That's an excellent idea. If I recall correctly ASP.NET is rendering this in
a very similar fashion.

Cheers,
Yee

-----Original Message-----
From: Simon Kitching [mailto:skitching@apache.org] 
Sent: Sunday, 15 January 2006 5:20 PM
To: MyFaces Discussion
Subject: Re: keep resulting html small (was: Re: commandLink)

On Sun, 2006-01-15 at 09:12 +0100, Mario Ivankovits wrote:
> Hi!
> > <a href="#"
> >
onclick="clear__5Fid0();document.forms['_id0'].elements['autoScroll'].value=
> >
getScrolling();document.forms['_id0'].elements['_id0:_link_hidden_'].value='
> >
_id0:pageID';if(document.forms['_id0'].onsubmit){if(document.forms['_id0'].o
> > nsubmit())
> >
document.forms['_id0'].submit();}else{document.forms['_id0'].submit();}retur
> > n false;" id="_id0:pageID"></a
> >   
> One thing which makes me felling a little bit uncomfortable is the size
> of the resulting html file.
> Say you have hundreds of command links in your jsf
> (tree/datatable/navigation) especially a tree with client side
> navigation tends to hold many entries - imagine the size of the
> resulting html file with all this onclick= on each command link.
> 
> Like the clear__ method we can render a submit__ javascript method which
> wraps all this stuff, cant we?
> 
> And maybe we can call this clear__ from within submit__ too, so this
> makes the above url something like:
> 
> > <a href="#"
> > onclick="return submit__5Fid0()" id="_id0:pageID"></a
> >   
> Or do I miss something?
> If not, I'll prepare a patch for it.

I'd really like to see this. It's been on my to-do list for a while.
When a page has a large table containing a commandLink, the resulting
html is currently *much* larger than it needs to be.

Rather than "return submit__5Fid0()", I'd like to see:
  onclick="return myfaces_submit(this)"
where the myfaces_submit function gets defined only once.

Is there any reason not to do this?

Note that there has recently been some discussion about "namespacing"
javascript methods. However moving to at least *having* a single
function definition is a good first step, even if "myfaces_submit" isn't
the final way to access that function.

Cheers,

Simon


Re: keep resulting html small (was: Re: commandLink)

Posted by Simon Kitching <sk...@apache.org>.
On Sun, 2006-01-15 at 09:12 +0100, Mario Ivankovits wrote:
> Hi!
> > <a href="#"
> > onclick="clear__5Fid0();document.forms['_id0'].elements['autoScroll'].value=
> > getScrolling();document.forms['_id0'].elements['_id0:_link_hidden_'].value='
> > _id0:pageID';if(document.forms['_id0'].onsubmit){if(document.forms['_id0'].o
> > nsubmit())
> > document.forms['_id0'].submit();}else{document.forms['_id0'].submit();}retur
> > n false;" id="_id0:pageID"></a
> >   
> One thing which makes me felling a little bit uncomfortable is the size
> of the resulting html file.
> Say you have hundreds of command links in your jsf
> (tree/datatable/navigation) especially a tree with client side
> navigation tends to hold many entries - imagine the size of the
> resulting html file with all this onclick= on each command link.
> 
> Like the clear__ method we can render a submit__ javascript method which
> wraps all this stuff, cant we?
> 
> And maybe we can call this clear__ from within submit__ too, so this
> makes the above url something like:
> 
> > <a href="#"
> > onclick="return submit__5Fid0()" id="_id0:pageID"></a
> >   
> Or do I miss something?
> If not, I'll prepare a patch for it.

I'd really like to see this. It's been on my to-do list for a while.
When a page has a large table containing a commandLink, the resulting
html is currently *much* larger than it needs to be.

Rather than "return submit__5Fid0()", I'd like to see:
  onclick="return myfaces_submit(this)"
where the myfaces_submit function gets defined only once.

Is there any reason not to do this?

Note that there has recently been some discussion about "namespacing"
javascript methods. However moving to at least *having* a single
function definition is a good first step, even if "myfaces_submit" isn't
the final way to access that function.

Cheers,

Simon