You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Martin Koci <ma...@gmail.com> on 2011/08/02 20:31:47 UTC

[core] dynamic script before (an equivalent for DialogRequest from Trinidad)

Hi,

has JSF an official API to achieve similar functionality as [1] ?

Purpose and use case:

1) JSF process partially view

2) JSF artifact creates and queues a request "render this script ...
before </body>"

3) new element script is created and rendered before </body>

this is not same same @Resource(target="body"). Also this must work with
partial response wihout explicit render="@all"


Any ideas?


Thanks,

Kočičák


[1]
https://svn.apache.org/repos/asf/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/DialogRequest.java





Re: [core] dynamic script before (an equivalent for DialogRequest from Trinidad)

Posted by Werner Punz <we...@gmail.com>.
There is no direct way to do that. I would love to have some kind of 
h:outputScript which could render against the body end. The reason for 
this is, you can get a significant performance boost if you push the 
script includes to the bottom of the page.

But anyway, the way to do this dynamically for ajax is to use the event 
handlers.

jsf.ajax.request(... onevent: funtion(event) {
   if(event.status === "complete") //insert script tag at the bottom
})

The problem with this approach simply is if you want to push script tags 
later dynamically, most modern browsers simply wont eval them anymore.

There is a technique where you push scripts after page loading into the 
head or after the head, this works on some browsers and on some it wont.
Funnily jQuery uses this method to cover the global Eval problem, which 
then fails on many modern browsers. We use a stage approach for this 
problem, we try to determine which method is the best for global eval 
and then use it - there are about 5-6 ways to achieve a global eval and 
depending on the browser you have to apply one method or the other.

HTML5 also has something for the late loading of scripts, but I have not 
looked to deeply into it yet.

Either way, if you need a late loading of scripts within an jsf ajax 
cycle it is probabyle better to include the script tag within the 
updated content (where our jsf javascript runtime can take care of it 
and does)

Or if you need a check whether the script already is included, use ajax 
to load the script run a global eval (both methods are impl methods on 
our _Runtime.js) manually and set a global variable/namespace which can 
be checked for later refreshes whether the script is already loaded.

The best bet is probably not to load any script lazily at all, bundle 
everything into one big compressed javascript file, and use a script src 
with defer set or push the script at the bottom of the page, if possible.


Werner




Am 03.08.11 10:39, schrieb Jakob Korherr:
> Hi,
>
> Nope, I don't think so. Maybe you can achieve it via a javascript
> event-handler on the client, but I actually don't know for sure. Maybe
> Werner can help you out!
>
> Regards,
> Jakob
>
> 2011/8/2 Martin Koci<ma...@gmail.com>:
>> Hi,
>>
>> has JSF an official API to achieve similar functionality as [1] ?
>>
>> Purpose and use case:
>>
>> 1) JSF process partially view
>>
>> 2) JSF artifact creates and queues a request "render this script ...
>> before</body>"
>>
>> 3) new element script is created and rendered before</body>
>>
>> this is not same same @Resource(target="body"). Also this must work with
>> partial response wihout explicit render="@all"
>>
>>
>> Any ideas?
>>
>>
>> Thanks,
>>
>> Kočičák
>>
>>
>> [1]
>> https://svn.apache.org/repos/asf/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/DialogRequest.java
>>
>>
>>
>>
>>
>
>
>



Re: [core] dynamic script before (an equivalent for DialogRequest from Trinidad)

Posted by Martin Koci <ma...@gmail.com>.
I'll try solution with a "mock" component before </body>. Component
fetchs all script requests from facesContext.attributes and renders
them. Also that component is autoRender=true so it is re-rendered in
every partial response.

Jakob Korherr píše v St 03. 08. 2011 v 11:10 +0200:
> Hi,
> 
> > Maybe you can override BodyRenderer to implement this.
> 
> For normal request: sure.
> For AJAX requests: whole body re-rendering would be necessary, thus
> not really usable.
> 
> Regards,
> Jakob
> 
> 2011/8/3 Çağatay Çivici <ca...@gmail.com>:
> > Maybe you can override BodyRenderer to implement this.
> > On Aug 3, 2011, at 11:39 AM, Jakob Korherr wrote:
> >
> > Hi,
> >
> > Nope, I don't think so. Maybe you can achieve it via a javascript
> > event-handler on the client, but I actually don't know for sure. Maybe
> > Werner can help you out!
> >
> > Regards,
> > Jakob
> >
> > 2011/8/2 Martin Koci <ma...@gmail.com>:
> >
> > Hi,
> >
> > has JSF an official API to achieve similar functionality as [1] ?
> >
> > Purpose and use case:
> >
> > 1) JSF process partially view
> >
> > 2) JSF artifact creates and queues a request "render this script ...
> >
> > before </body>"
> >
> > 3) new element script is created and rendered before </body>
> >
> > this is not same same @Resource(target="body"). Also this must work with
> >
> > partial response wihout explicit render="@all"
> >
> >
> > Any ideas?
> >
> >
> > Thanks,
> >
> > Kočičák
> >
> >
> > [1]
> >
> > https://svn.apache.org/repos/asf/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/DialogRequest.java
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> > Jakob Korherr
> >
> > blog: http://www.jakobk.com
> > twitter: http://twitter.com/jakobkorherr
> > work: http://www.irian.at
> >
> > Çağatay Çivici
> > Principal Consultant
> > PrimeFaces Lead | JSF EG Member
> >
> > Prime Teknoloji
> > Bilkent Cyberpark, A-303d
> > 06800 Ankara/Turkey
> > Tel: +90 312 265 05 07
> > http://www.prime.com.tr
> >
> 
> 
> 



Re: [core] dynamic script before (an equivalent for DialogRequest from Trinidad)

Posted by Jakob Korherr <ja...@gmail.com>.
Hi,

> Maybe you can override BodyRenderer to implement this.

For normal request: sure.
For AJAX requests: whole body re-rendering would be necessary, thus
not really usable.

Regards,
Jakob

2011/8/3 Çağatay Çivici <ca...@gmail.com>:
> Maybe you can override BodyRenderer to implement this.
> On Aug 3, 2011, at 11:39 AM, Jakob Korherr wrote:
>
> Hi,
>
> Nope, I don't think so. Maybe you can achieve it via a javascript
> event-handler on the client, but I actually don't know for sure. Maybe
> Werner can help you out!
>
> Regards,
> Jakob
>
> 2011/8/2 Martin Koci <ma...@gmail.com>:
>
> Hi,
>
> has JSF an official API to achieve similar functionality as [1] ?
>
> Purpose and use case:
>
> 1) JSF process partially view
>
> 2) JSF artifact creates and queues a request "render this script ...
>
> before </body>"
>
> 3) new element script is created and rendered before </body>
>
> this is not same same @Resource(target="body"). Also this must work with
>
> partial response wihout explicit render="@all"
>
>
> Any ideas?
>
>
> Thanks,
>
> Kočičák
>
>
> [1]
>
> https://svn.apache.org/repos/asf/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/DialogRequest.java
>
>
>
>
>
>
>
>
> --
> Jakob Korherr
>
> blog: http://www.jakobk.com
> twitter: http://twitter.com/jakobkorherr
> work: http://www.irian.at
>
> Çağatay Çivici
> Principal Consultant
> PrimeFaces Lead | JSF EG Member
>
> Prime Teknoloji
> Bilkent Cyberpark, A-303d
> 06800 Ankara/Turkey
> Tel: +90 312 265 05 07
> http://www.prime.com.tr
>



-- 
Jakob Korherr

blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at

Re: [core] dynamic script before (an equivalent for DialogRequest from Trinidad)

Posted by Çağatay Çivici <ca...@gmail.com>.
Maybe you can override BodyRenderer to implement this.

On Aug 3, 2011, at 11:39 AM, Jakob Korherr wrote:

> Hi,
> 
> Nope, I don't think so. Maybe you can achieve it via a javascript
> event-handler on the client, but I actually don't know for sure. Maybe
> Werner can help you out!
> 
> Regards,
> Jakob
> 
> 2011/8/2 Martin Koci <ma...@gmail.com>:
>> Hi,
>> 
>> has JSF an official API to achieve similar functionality as [1] ?
>> 
>> Purpose and use case:
>> 
>> 1) JSF process partially view
>> 
>> 2) JSF artifact creates and queues a request "render this script ...
>> before </body>"
>> 
>> 3) new element script is created and rendered before </body>
>> 
>> this is not same same @Resource(target="body"). Also this must work with
>> partial response wihout explicit render="@all"
>> 
>> 
>> Any ideas?
>> 
>> 
>> Thanks,
>> 
>> Kočičák
>> 
>> 
>> [1]
>> https://svn.apache.org/repos/asf/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/DialogRequest.java
>> 
>> 
>> 
>> 
>> 
> 
> 
> 
> -- 
> Jakob Korherr
> 
> blog: http://www.jakobk.com
> twitter: http://twitter.com/jakobkorherr
> work: http://www.irian.at

Çağatay Çivici
Principal Consultant
PrimeFaces Lead | JSF EG Member

Prime Teknoloji
Bilkent Cyberpark, A-303d
06800 Ankara/Turkey
Tel: +90 312 265 05 07
http://www.prime.com.tr


Re: [core] dynamic script before (an equivalent for DialogRequest from Trinidad)

Posted by Jakob Korherr <ja...@gmail.com>.
Hi,

Nope, I don't think so. Maybe you can achieve it via a javascript
event-handler on the client, but I actually don't know for sure. Maybe
Werner can help you out!

Regards,
Jakob

2011/8/2 Martin Koci <ma...@gmail.com>:
> Hi,
>
> has JSF an official API to achieve similar functionality as [1] ?
>
> Purpose and use case:
>
> 1) JSF process partially view
>
> 2) JSF artifact creates and queues a request "render this script ...
> before </body>"
>
> 3) new element script is created and rendered before </body>
>
> this is not same same @Resource(target="body"). Also this must work with
> partial response wihout explicit render="@all"
>
>
> Any ideas?
>
>
> Thanks,
>
> Kočičák
>
>
> [1]
> https://svn.apache.org/repos/asf/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/DialogRequest.java
>
>
>
>
>



-- 
Jakob Korherr

blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at