JSF CommandLink not working in Firefox after full reRender form

I have a JSF 1.2 application (Sun RI, Facelets, Richfaces) that was used only in IE6 browsers. Now we must also support Firefox (yes!).

On one of my pages, I have a form containing a button that will redisplay the entire form. After re-rendering, some links ( <h:commandLink/>) are added to this form .

JSF code is as follows:

<h:form id="foobar">
    ...
    <a4j:commandButton ... reRender="foobar"/>
    ...
    <h:commandLink .../>
</h:form>

My problem is related to the HTML generated by the link component, which looks like this:

<a href="#" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.forms['foobar'],'...','');}return false">bla bla</a>

(for information jsfcljs, this is the Javascript function generated by the component <h:commandLink/>)

, document.forms["foobar"] , , Ajax, Firefox ( IE6).

Javascript, Ajax.

, document.getElementById("foobar"); Ajax, Firefox ...

Javascript:

function test() {
    var e = document.forms;
    var tmp = "";
    for (i = 0; i < e.length; i++) {
        tmp = tmp + e[i].id + " ; ";
    }
    alert(tmp);
}

Ajax, :

someForm ; anotherForm ; foobar ; // Before Ajax call on FF 
someForm ; anotherForm ; // After Ajax call on FF. PROBLEM HERE!

someForm ; anotherForm ; foobar ; // Before Ajax call on IE6 
someForm ; anotherForm ; foobar ; // After Ajax call on IE6

:

Ajax , a4j reRender-ed ( , foobar) DOM, document.forms. foobar . Firefox document.forms, IE6 . document.forms["foobar"] undefined Ajax.

- reRender, - , . , .

, , reRender. ?


Javascript :

function dpf(f) {
    var adp = f.adp;
    if (adp != null) {
        for (var i = 0; i < adp.length; i++) {
            f.removeChild(adp[i]);
        }
    }
};

function apf(f, pvp) {
    var adp = new Array();
    f.adp = adp;
    var ps = pvp.split(',');
    for (var i = 0, ii = 0; i < ps.length; i++, ii++) {
        var p = document.createElement("input");
        p.type = "hidden";
        p.name = ps[i];
        p.value = ps[i + 1];
        f.appendChild(p);
        adp[ii] = p;
        i += 1;
    }
};

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

<h:commandLink> onclick jsfcljs(document.forms['foobar'], 'someId', ''), jsfcljs(undefined, 'someId', ''). , f, Javacript, , f is undefined.

+3
2

- HTML-, .

, id:

-. , , , , .

- inline onclick , document.getElementById( "foobar" ) document.forms [ "foobar" ]

+2

Sun Mojarra 1.2 ( 4 ). . Sun Mojarra 1.2 1.2_14, . JSF /WEB-INF/lib .

0

Source: https://habr.com/ru/post/1723852/


All Articles