如何使用jQuery在JSF2.0中选择表单元素及其子元素

时间:2012-02-07 11:57:44

标签: jquery jsf-2

我在这样的JSF2.0中有一个表单     

    <h:form id="validationFrom" >

        <div id="mandotary" >

            <h:panelGrid columns="4"
                         border="1"
                         width="50%"
                         style=""
                         columnClasses="asteriskColumns, nameColumns" >

                <h:outputLabel value="*" style="color: red;" />
                <h:outputLabel value="Heading: " />
                <h:inputText id="heading" value="#{validation.heading}" />
                <h:message id="headingMessage" for="heading" style="color: red" />

                <h:outputLabel value="*" />
                <h:outputLabel value="Select Category Type :" />
                <h:selectOneRadio id="selectCategoryRadioButton"
                                  rendered=""
                                  value="#{validation.selectedRadioButton}"
                                  layout="layoutDirection">

                    <f:selectItems value="#{validation.radioButtonItems}"/>

                </h:selectOneRadio>
                <h:panelGroup />

                <h:outputLabel value="*"
                               rendered=""/>

                <h:outputLabel value="Broad Category :"
                               rendered=""/>
                <h:selectOneMenu id="broadCategory"
                                 rendered=""
                                 value="#{validation.selectedBroadCategory}" >

                    <f:selectItems value="#{validation.broadCategoryItemsList}"/>

                </h:selectOneMenu>
                <h:message id="broadCategoryMessage" for="broadCategory" style="color: red" />

                <h:outputLabel value="*" />
                <h:outputLabel value="Sub Category :" />
                <h:selectOneMenu id="subCategory"
                                 value="#{validation.selectedSubCategory}"
                                 style="width: 250px;">

                    <f:selectItem itemLabel="---Select---" noSelectionOption="true" />
                    <f:selectItems value="#{validation.subCategoryItemsMap}"/>

                </h:selectOneMenu>
                <h:message id="subCategoryMessage" for="subCategory" style="color: red" />

                <h:outputLabel value="*" style="color: red;" />
                <h:outputLabel value="Description: " />
                <h:inputText id="description" value="#{validation.description}" />
                <h:message id="descriptionMessage" for="description" style="color: red" />

            </h:panelGrid>

        </div>

        <h:commandButton id="saveButton"
                         value="Save"
                         action ="null"/>


        <h:commandButton id="cancelButton"
                         value="Cancel"
                         action="null" />

    </h:form>

</h:body>

现在我想用类mandoroty选择form和div,所以我可以检查div中的所有元素。我正在尝试这个,但它无法正常工作

(function($){

    var mandotoryFieldsArray = $("#validationFrom div.mandotary")
    var test;

})(jQuery); //end of (function($){}

该行给了我null数组。为什么?我在选择表单元素时做错了什么?

1 个答案:

答案 0 :(得分:0)

尝试使用

$("[@id=validationFrom :mandotary]");

参考博客http://rockycode.com/blog/ids-jsf-used-jquery/