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 11:41:57 UTC

Re: keep resulting html small

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

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