我可以使用JavaScript触发IceFaces动作吗?

时间:2010-09-22 13:29:47

标签: java javascript jsf icefaces

如果我有一个简单的按钮:

   <ice:panelGroup> 
            <ice:commandButton value="foobar" 
            action="#{fileManager.openNoFlashVisiblePopup}" />
   </ice:panelGroup>

是否可以仅使用javascript触发openNoFlashVisiblePopup操作?我知道IceFaces有一个JavaScript桥,但我不知道看到一个简单的方法。

我需要这样做,因为我有一大块JavaScript可以检测Flash,我需要显示一个IceFaces弹出窗口。

2 个答案:

答案 0 :(得分:1)

一种方法是按ID获取按钮元素并调用其click()函数。

document.getElementById('clientId').click();

您只需要为表单和按钮添加固定的id,以便您可以在Javascript代码中将生成的HTML ID用作clientId

答案 1 :(得分:0)

我知道我看到这一点有点迟了,但是处理这个问题的正确方法(减去可能过于繁琐的错误检查)是:

        // There's a <div> that looks like: <div class="portletfaces-bridge-body" id="A8660">.
    // We'll find it and pull out the value of the ID to build elementId like: A8660:wtfForm:editeventparent
    var div = null; 
    var divCollection = document.getElementsByTagName("div");
    for (var i=0; i<divCollection.length; i++) {
        if(divCollection[i].getAttribute("class") == "portletfaces-bridge-body") {
            div = divCollection[i];
            break;
        } 
    }
    if (div == null){
        alert("could not find div portletfaces-bridge-body.");
        return;
    }

    // Pull the id out of divInnerText.
    var id = div.getAttribute("id");
    if (id == null){
        alert("id was null");
    }

    // prepare initializes fields to null so rendered cannot begin until both itemId and parentId are set.
    var prepare = document.getElementById(id + ":wtfForm:editeventprepare");
    if (prepare == null){
        alert("editeventprepare element was not found.");
        return;
    }
    prepare.click();