Recently I am studying the JSF codes.
But I encounter a problem about the basis of JSF.
In a xhtml file I saw others write <h:form method="post" id="loginForm" > , when I visit the jsf page, it generates HTML code which is <form id="loginForm" name="loginForm" method="post" action="/quizApp/login.jsf" enctype="application/x-www-form-urlencoded">
I know the tag <h:form> of JSF means <form> of HTML.
But the problem is how it defines the action???   in the <h:form method="post" id="loginForm" > there is no definition about the form's action and the enctype attribute.   I try to find if it is defined in the web.xml or 
faces-config.xml..   But I can't find any.Ask some sophisticated professionals for help me solve this problem..!
Thanks.

解决方案 »

  1.   

    Sorry!i've never used JSF
      

  2.   

    页面上总要有按钮,点击一下才提交的咯
    <a4j:commandButton id="login_button"
    styleClass="rich-button default" 
    value="Login"  
    reRender="greeting" 
    action="#{login.validate}" //这里添加action
    />
    这个按钮我用于最简单的登录页面上
      

  3.   

    Thx . But the actual code is not that. I paste my code.<h:form method="post" id="loginForm" >
    <table align="center">
    <tr>
    <td><h:messages layout="table" style="color:red" /></td>
    </tr>
    <tr align="center">
    <td colspan="3"><h:outputLabel for="lang" value="Please Select Language 請選擇語言 请选择语言" /></td>
    </tr>
    <tr align="center">
    <td colspan="3">
    <h:selectOneMenu id="lang" value="#{staff.language}" required="true" requiredMessage="Please choose a language" immediate="true" onchange="this.form.submit( );"
           valueChangeListener="#{staff.toggleLanugage}" >
    <f:selectItem itemLabel="English" itemValue="en" />
    <f:selectItem itemLabel="繁體中文" itemValue="zh_HK" />
    <f:selectItem itemLabel="简体中文" itemValue="zh_CN" />
    <f:selectItem itemLabel="Thai" itemValue="th_TH" />
    </h:selectOneMenu></td>
    </tr>
    <tr><td height="10px"></td></tr>
    </table>
    </h:form>
    <form method="post" id="loginForm" action="/quizApp/j_spring_security_check" enctype="application/x-www-form-urlencoded">
    <table align="center">
    <tr align="center">
    <td colspan="3"><h:outputText value="Please Login 請登入 请登入 " /></td>
    </tr>
    <tr>
    <td>Login Name:</td>
    <td><h:inputText name="j_username" id="j_username" required="true" requiredMessage="Login Name is required" validatorMessage="Max length is 10">
    <f:validateLength maximum="10" />
    </h:inputText></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><h:inputSecret name="j_password" id="j_password" required="true" requiredMessage="Password is required" validatorMessage="Max length is 10">
    <f:validateLength maximum="10" />
    </h:inputSecret></td>
    <td><h:commandButton type="submit" value="OK" id="login" /></td>
    </tr>
    </table>
    </form>
      

  4.   

    this page is not written by myself..  I only wanna know the principle about the action of form in JSF...
      

  5.   

    jsf跟之前的jsp是不大一样的,你自己也看到了,同一个页面出现了两个form,jsf的action提交写法变得更细化了,比如细化到一个按钮,一个表单,同一个form里可以定义多个动作,同一个页面允许多个form等等。建议你还是去看看jsf的白皮书吧~
    最简单的action写法就是
    <h:form>
    <h:inputText value="#{verifyCode.verifyCode}">
    </h:inputText>
    <a4j:commandButton id="login_button"
    styleClass="rich-button default" 
    value="login"  
    reRender="greeting" 
    action="#{authenticator.authenticate}" 
    />
    </h:form>
      

  6.   

    so can anybody read it and explain how to implement the action in the code mentioned??
      

  7.   

    两个form,上面一个form里
    <h:selectOneMenu id="lang" value="#{staff.language}" required="true" requiredMessage="Please choose a language" immediate="true" onchange="this.form.submit( );"
           valueChangeListener="#{staff.toggleLanugage}" >注意这句里的valueChangeListener,也就是当值改变的时候,实时触发监听器来进行一些动作,这里就是实时改变页面的语言
    下面一个form是普通form,不需要解释了吧?
      

  8.   

    oh... it seems I've understood some about that .  But can u tell me where the Listener should be..?  I find this:<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener> <listener>
    <listener-class>
    org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>But I can't open it coz it's a class.  Is the action value written into this listener statically?  So the listener is only for this one form???
      

  9.   

    does that mean if no action url is defined, it submit to the page itself?