h:commandLink open in new browser window

落爺英雄遲暮 提交于 2020-01-15 10:45:21

问题


I want to open a new window, configured with height and width, all while using < h:commandLink >

<h:commandLink id="zyzid" value="click me" action="#{test.testDo}"  target="_blank" />

this renders into:

<a onclick="mojarra.jsfcljs(document.getElementById('myForm'),{'myForm:xyzid':'myForm:xyzid'},'_blank');return false" href="#" id="myForm:xyzid">click me</a>

I looked at jsfcljs() function. It submits the form with target="_blank", but i don't see window.open() anywhere. So, how would I be able to alter this code to change new window's height and width?

for reference:

mojarra.jsfcljs = function jsfcljs(f, pvp, t) {
    mojarra.apf(f, pvp);
    var ft = f.target;
    if (t) {
        f.target = t;
    }
    f.submit();
    f.target = ft;
    mojarra.dpf(f);
};

回答1:


I found a few relevant links, and this and I arrived at this solution, which seems to work for me. h:commandLink opens a new page, and I get to manipulate it's width and height. This involves slightly modifying/overwriting the mojarra.jsfcljs function. It opens a window with standard window.open() (triggered by onclick) and associates the form it is submitting with that window.

$(window).load(function(){
            mojarra.jsfcljs = function jsfcljs(f, pvp, t) {
                mojarra.apf(f, pvp);
                var ft = f.target;
                if (t) {
                    if (t.indexOf('options') != -1){
                        f.target = '_blank' + new Date().getTime();
                        var options = t.substring(t.indexOf('optionts') + 9);
                        window.open('', f.target, options); 
                    }
                    else{
                        f.target = t;
                    }
                }

                f.submit();
                f.target = ft;
                mojarra.dpf(f);
              };
        });

markup:

< h:commandLink id="viewLink"  action="#{testBean.doTest}" value="h:commandLink"  target="options:height=200, width=300" />


来源:https://stackoverflow.com/questions/19101713/hcommandlink-open-in-new-browser-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!