0

我正在尝试 JSF,但我无法调用映射到操作属性的方法我的 JSF 页面如下,

 <?xml version="1.0" encoding="ISO-8859-1" ?>
 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
 <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
 <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title>MAP STUDENT-COURSE</title>
        <link rel="stylesheet" href="<%=request.getContextPath()%>/demo.css" type="text/css" />
        <script type="text/javascript">
            window.onload = function(){
                    var validateFN = function(){
                        var selectObj = document.getElementById("selectOptionForm:operationTypeID");
                        var selectFN = function(){                      
                            var selectedOp = selectObj.options[selectObj.selectedIndex].value;
                            if(selectedOp == "0" || selectedOp == 0){
                                alert(" Select appropriate option.... ");                                   
                            }else{
                                document.selectOptionForm.submit();
                            }   
                        }

                        if(selectObj != null){  
                            selectObj.onchange = selectFN;                          
                        }
                    }
                    validateFN();

            }
        </script>
    </head>
    <body>
        <f:view>
            <h:form id="selectOptionForm">
                <h:panelGrid columns="2" headerClass="headerRow" rowClasses="oddRow,evenRow">
                    <f:facet name="header">
                        <h:outputText value="SELECT OPERATION" />
                    </f:facet>
                    <h:outputText value="SELECT OPTION" />
                    <h:selectOneMenu id="operationTypeID" value="#{studentCourseBean.operationType}" valueChangeListener="#{studentCourseBean.fetchCombo}">
                        <f:selectItem  itemLabel="SELECT"  itemValue="0"  />    
                    <f:selectItem  itemLabel="MAP STUDENT"  itemValue="addStudent"  />
                        <f:selectItem  itemLabel="MAP COURSE"  itemValue="addCourses"  />
                    </h:selectOneMenu>
                </h:panelGrid>
            </h:form>
            <br />
            <br />
            <br />
            <h:form id="addStudentForm" rendered="#{(studentCourseBean.addByStudents && !studentCourseBean.addByCourses)}">
                <h:panelGrid columns="2" headerClass="headerRow" rowClasses="oddRow,evenRow" footerClass="headerRow">
                    <f:facet name="header">
                        <h:outputText value="MAP STUDENT" />
                    </f:facet>
                    <h:outputText value="SELECT STUDENT" />
                    <h:selectOneMenu  id="studentID" value="#{studentCourseBean.selectedStudentId}">
                        <f:selectItems value="#{studentCourseBean.studentDropBox}" />
                    </h:selectOneMenu>
                    <h:outputText value="SELECT COURSE'S" />
                    <h:selectManyListbox id="courseID" value="#{studentCourseBean.selectedCourseList}" size="5">
                        <f:selectItems value="#{studentCourseBean.courseDropBox}" />
                    </h:selectManyListbox>
                    <f:facet name="footer">
                        <h:panelGroup>
                            <h:commandButton id="enterButton" type="submit" value="ENTER" action="#{studentCourseBean.addStudentAction}" />
                            <h:commandButton id="cancelButton" type="submit" value="CANCEL" action="#{studentCourseBean.cancelAction}" />
                        </h:panelGroup>
                    </f:facet>
                </h:panelGrid>
            </h:form>
            <h:form id="addCourseForm" rendered="#{(!studentCourseBean.addByStudents && studentCourseBean.addByCourses)}">
                <h:panelGrid columns="2" headerClass="headerRow" rowClasses="oddRow,evenRow" footerClass="headerRow">
                    <f:facet name="header">
                        <h:outputText value="MAP COURSE" />
                    </f:facet>
                    <h:outputText value="SELECT COURSE" />
                    <h:selectOneMenu  id="courseID" value="#{studentCourseBean.selectedCourseList}">
                        <f:selectItems value="#{studentCourseBean.courseDropBox}" />
                    </h:selectOneMenu>
                    <h:outputText value="SELECT STUDENTS" />
                    <h:selectManyListbox id="studentID" value="#{studentCourseBean.selectedStudentList}" size="5">
                        <f:selectItems value="#{studentCourseBean.studentDropBox}" />
                    </h:selectManyListbox>
                    <f:facet name="footer">
                        <h:panelGroup>
                            <h:commandButton id="enterCrButton" type="submit" value="ENTER" action="#{studentCourseBean.addCourseAction}" />
                            <h:commandButton id="cancelCrButton" type="submit" value="CANCEL" action="#{studentCourseBean.cancelAction}" />
                        </h:panelGroup>
                    </f:facet>
                </h:panelGrid>
            </h:form>   
        </f:view>   
    </body>
 </html>

这里我说的是第二种形式,它的 id 是“addCourseForm”,

请注意,我的页面中有两个表单,第一个是“addStudentForm”表单,效果很好,但是在我的第二个表单中我无法提交,任何人都可以告诉我为什么“addCourseForm”没有按要求工作,

我在viewedScope 中的支持bean,我正在使用JSF 2.0 注释,等待回复

4

0 回答 0