简体   繁体   English

JSF 1.2 + Javascript + AJAX

[英]JSF 1.2 + Javascript + AJAX

I use jsf 1.2, richfaces 3.3.3. 我使用jsf 1.2,richfaces 3.3.3。 I've written the javascript fuction and want to use it as onclick on a4j:commandButton. 我已经编写了JavaScript函数,并希望将其用作ona4j:commandButton的onclick。

Function: 功能:

function simpleFunction(){
    var x = document.getElementById('check').value;
    if(x != null){
        alert("NOT NULL");
    }
} 

Form: 形成:

 <h:form>
        <h:inputText id="check" value="myvalue" style="display: none"/>
        <h:outputText value="#{crossReferenceMsg.min3}" style="font-size: 11px; color:red; font-weight: bold"/><br/>
        <h:outputLabel value="#{crossReferenceMsg.searchName}" for="tbSearchFilter"
                       style="font-size: 14px;font-weight: bold;"/>
        <h:inputText id="tbSearchFilter" value="#{CrossReferenceBean.searchText}">
        </h:inputText>
        <a4j:commandButton id="btnSearchCrossReference"
                           onclick="simpleFunction()"
                           action="#{CrossReferenceBean.search}"
                           value="#{crossReferenceMsg.search}"
                           reRender="dvFilters"/>
        <rich:messages for="tbSearchFilter"/>
        <rich:hotKey key="return"
                     handler="#{rich:element('btnSearchCrossReference')}.click()"
                     selector="#dvSearchCrossReference"/>
    </h:form>

But it does not work - in GoogleChrome debugger I can see, that variable x = undefined. 但这是行不通的-在GoogleChrome调试器中,我看到的是变量x =未定义。 Where did I make a mistake? 我在哪里弄错了?

add prependId="false" to your h:form . prependId="false"添加到您的h:form

in this case, by default, form id (something like j_idt..., which is automatically set by jsf) is prepended to all the component ids nested in your form. 在这种情况下,默认情况下,表单ID(类似于jsf自动设置的j_idt ...之类)将嵌套在表单中的所有组件ID之前。 so your actual h:inputText id is not "check". 因此您实际的h:inputText ID不是“检查”。 you can see that if you inspect html source of your page. 您可以看到,如果您检查页面的html源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM