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.
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.
<a4j:commandButton id="login_button"
styleClass="rich-button default"
value="Login"
reRender="greeting"
action="#{login.validate}" //这里添加action
/>
这个按钮我用于最简单的登录页面上
<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>
最简单的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>
<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,不需要解释了吧?
<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???