Chủ đề: JSF controller class
-
13-10-2015, 07:37 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
JSF controller class
Chào mọi người. Em đang tự học JSF và đang tạo 1 controller class đơn giản để lấy input từ xhtml.Các class của em như sau:
BMI ;
private static int height;
private static double bmi;
private static String bmiCategory;
public static int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public static int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public BMI(int weight, int height) {
super();
this.weight = weight;
this.height = height;
bmi();
bmiCategory();
}
public BMI() {
super();
// TODO Auto-generated constructor stub
}
public double bmi () {
bmi = 1.0*(703 * weight) / (height * height );
return bmi;
}
public String bmiCategory () {
if (bmi() < 18.5) {
bmiCategory = "Under weight";
} else if (bmi() <= 24.9) {
bmiCategory = "Normal";
} else if (bmi() <= 29.9) {
bmiCategory = "Over weight";
} else {
bmiCategory = "Obese";
}
return bmiCategory;
}
}
Và đây là file xhtml:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns="http://primefaces.org/ui">
<h:head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>[untitled document]</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" />
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</h:head>
<h:body>
<h:form action= "#" method = "post">
<panel id="panel" header="BMI Calculator" style="margin-bottom:10px;">
<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
<hanelGrid columns="2" cellpadding="5">
<hutputLabel for="weight" value="Weight(in lbs):" />
<p:inputText id="weight" required="true" value = "#{BmiController.Weight}"/>
<hutputLabel for="height" value="Height(in inches):" />
<p:inputText id="height" required="true" value = "#{BmiController.Height}"/>
</hanelGrid>
</panel>
<p:commandButton action ="BmiController.bmiBean" value="Calculator" update="panel" >
</p:commandButton>
</h:form>
</h:body>
Mọi người cho em hỏi làm cách nào để tạo controller class để lấy dữ liệu input từ textbox trong file xhtml của em ạView more random threads:
- Giúp đỡ về game phiêu lưu
- Xin code image editor đơn giản
- Cho em hỏi là chỗ in đậm (các cái veccn.get....) là gì ạ
- [Xin giúp đỡ] Về việc đưa webservice lên mạng
- bài toán
- Hỏi về lớp và đối tượng trong Java!
- lỗi khi chạy java
- ai làm hộ em cái nút reset này trong bài này với :3
- Điểm mạnh của framework hibernate
- Tách Chuỗi Trong Java
Pallet nhựa Long An đã trở thành một trong những lựa chọn phổ biến cho nhu cầu vận chuyển và lưu trữ hàng hóa trong nhiều ngành công nghiệp. Với đặc tính nhẹ nhàng, chắc chắn và dễ vận chuyển, các...
Thanh lý pallet nhựa Long An giá rẻ