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:
- [Help]Ứng Dụng Sổ Tay Cá Nhân trên Android?
- Không Import được Project vào JBuilder 2008
- Java and Flickr - Rắc rối với tính thừa kế giữa Lớp Chính và các lớp phụ
- Tham biến array trong Java
- [help] nhập môn thế nào?
- Học Java từ đầu như thế nào anh chị ơi và làm sao để học được ạ
- Tìm giúp chỗ sai lập trình java cơ bản ?
- Tách Chuỗi Trong Java
- Xử lý ảnh trong java
- Cần giúp gửi dữ liệu tới nhiều sever
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ẻ