Validation from
Enter value
Enter success
Enter value
Enter success
Project
MyName.xhtml
Java 2016
<?xml version='1.0' encoding='UTF-8' ?> <!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" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core"> <h:head> <title>Welcome to Aptech Computer Education </title> </h:head> <h:body> <h1>Welcome to Aptech Computer Education</h1> <f:view> <h:form> Enter your first name<br/> <h:inputText id="first" value="#{myNameManagedBean.firstname}" required="true" requiredMessage="Enter your firstname!"></h:inputText> <h:message for="first" style="color: red"/> <br/> Enter your last name<br/> <h:inputText id="last" value="#{myNameManagedBean.lastname}" required="true" requiredMessage="Enter your lastname!"></h:inputText> <h:message for="last" style="color: red"/> <br/> <h:commandButton value="Enter" action="#{myNameManagedBean.login()}"></h:commandButton> </h:form> </f:view> </h:body> </html>
Welcome.xhtml
Java 2016
<?xml version='1.0' encoding='UTF-8' ?>
<!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"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Welcome</title>
</h:head>
<h:body>
You have successfully Logged in #{myNameManagedBean.firstname} #{myNameManagedBean.lastname}
</h:body>
</html>
MyNameManagedBean.java
Java 2016
package controller;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class MyNameManagedBean {
private String firstname;
private String lastname;
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String login() {
if (firstname.equals("Duong") && lastname.equals("Dai")) {
return "Welcome";
} else {
return "MyName";
}
}
}
Trắc nghiệm đúng 50%
0 nhận xét:
Post a Comment