You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Richard J. Barbalace" <rj...@MIT.EDU> on 2005/11/02 18:54:33 UTC

JavaScript in jsCookMenu component?

Hi.

I apologize if this is the wrong list to send comments/questions/bugs, but if
there is a better place it was not easily findable on the MyFaces website or
wiki.

A question was recently asked in the Sun developer forums about using JavaScript
with the jsCookMenu component.  You can see the question and my response there:
    http://forum.java.sun.com/thread.jspa?threadID=672534&tstart=0

There was a change made to the cmItemMouseUp() JavaScript function by royalts
(Thomas Spiegl) to make the form submittal work with MyFaces actions, but this
code breaks attempts to include JavaScript calls in the menu, such as might be
used to pop up a help window or perform other non-JSF actions.

As mentioned in the forum above, I modified this function for my particular
application to check whether certain non-JSF actions (JavaScript calls and
outside http requests) are included in the menu as follows:

function cmItemMouseUp (obj, index)
{
.....
    if (link != null)
    {
        // changes by richard (Richard J. Barbalace)
            if (link.match(/^\w*:javascript:/) != null ) {
            link = link.replace(/^\w*:javascript:/, "javascript:");
            target = '_self';
            window.open (link, target);
        } else if (link.match(/^\w*:http:/) != null ) {
            link = link.replace(/^\w*:http:/, "http:");
            window.open (link, target);
        } else {
            // changes by royalts (Thomas Spiegl)
            var dummyForm = document.forms['linkDummyForm'];
            dummyForm.elements['jscook_action'].value = link;
            dummyForm.submit();
        }
    }
.....
}

I have only been using MyFaces for a few months, so there may be a better way to
do this, but I think many application developers would appreciate a similar
solution in the next version of MyFaces.  If it is helpful, feel free to take
or modify my code.


Re: JavaScript in jsCookMenu component?

Posted by Simon Kitching <sk...@obsidium.com>.
Richard J. Barbalace wrote:
> Hi.
> 
> I apologize if this is the wrong list to send comments/questions/bugs, but if
> there is a better place it was not easily findable on the MyFaces website or
> wiki.

This list seems appropriate to me; you're posting a patch to the code.

> 
> A question was recently asked in the Sun developer forums about using JavaScript
> with the jsCookMenu component.  You can see the question and my response there:
>     http://forum.java.sun.com/thread.jspa?threadID=672534&tstart=0
> 
> There was a change made to the cmItemMouseUp() JavaScript function by royalts
> (Thomas Spiegl) to make the form submittal work with MyFaces actions, but this
> code breaks attempts to include JavaScript calls in the menu, such as might be
> used to pop up a help window or perform other non-JSF actions.
> 
> As mentioned in the forum above, I modified this function for my particular
> application to check whether certain non-JSF actions (JavaScript calls and
> outside http requests) are included in the menu as follows:
> 
> function cmItemMouseUp (obj, index)
> {
> .....
>     if (link != null)
>     {
>         // changes by richard (Richard J. Barbalace)
>             if (link.match(/^\w*:javascript:/) != null ) {
>             link = link.replace(/^\w*:javascript:/, "javascript:");
>             target = '_self';
>             window.open (link, target);
>         } else if (link.match(/^\w*:http:/) != null ) {
>             link = link.replace(/^\w*:http:/, "http:");
>             window.open (link, target);
>         } else {
>             // changes by royalts (Thomas Spiegl)
>             var dummyForm = document.forms['linkDummyForm'];
>             dummyForm.elements['jscook_action'].value = link;
>             dummyForm.submit();
>         }
>     }
> .....
> }
> 
> I have only been using MyFaces for a few months, so there may be a better way to
> do this, but I think many application developers would appreciate a similar
> solution in the next version of MyFaces.  If it is helpful, feel free to take
> or modify my code.

I'd also be keen to see support for "javascript:" and absolute URLs in 
jscookmenu. In fact, for the project I'm currently working on we have a 
very similar modification to add exactly this functionality.

I'd rather see detection of *any* protocol on  the front of the URL 
rather than checking just for "http:". The protocols "https:", "mail:" 
etc are also useful.

== proposal: ==
The URL *always* has "menu_id:" on the start, so presumably the jscript 
could just strip this ID off then look for a ":" before any occurrence 
of "/" or "?". If that is present, then the URL is "absolute". And if 
that is not present but the URL contains a "/" then it isn't an action 
so treat that as a local URL.

Comments?

Regards,

Simon