I am studying Managed Beans right now. I need to use html file to get the data and post them on the next page. I need to use ManagedBean. I am required to use .html file. I can't use JSF because we haven't began to study it yet.
Question: How can I set the value first name in the Voter.java class and then post it the new page?
I tried to use:
First Name:<input action="UserInfo.setFirstName()" type="text" name="fname" maxlength="30"
value="" pattern="[a-zA-Z]{1,30}" title="Please enter first name! Min 1
letter"required/><br>
but it doesn't work after I deploy the program.
welcome.html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html>
<head>
<title>Welcome Form</title>
</head>
<body>
<div style="text-align:center">
<h1>Welcome</h1>
<form action="summary.html">
<fieldset>
<legend>Form:</legend>
<fieldset>
<legend>Personal Information:</legend>
First Name:<input action="UserInfo.setFirstName()" type="text" name="fname" maxlength="30"
value="" pattern="[a-zA-Z]{1,30}" title="Please enter first name! Min 1
letter"required/><br>
</fieldset>
<p></p>
<input type="submit" value="Submit" />
</fieldset>
</form>
</div>
</body>
</html>
summary.html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html>
<head><title>Thank you</title></head>
<body>
<h1>Information Summary</h1>
<li action="SubmissionController.getFirstName()"><b>First Name:</b>
</body>
</html>
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="userinfo")
@SessionScoped
public class UserInfo {
private String fname;
public UserInfo() {}
public String getFirstName() {
return fname;
}
public void setFirstName(String fname) {
this.fname = fname;
}
}
So the answer is yes I can use simple HTML with ManagedBeans. I just used Java Servlets, HTML and CDI managed beans. I had to use @Inject the reference of class type where is the bean and I used it in the class where I use Servlets. In the bean class I used Named and SessionScoped beans. So the beans store the info that is submitted by the user.