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:
- generic 1 mảng trong java
- Cần giúp về LỚP TRỪU TƯỢNG
- ai giúp em viết ứng dụng web đơn giản với
- lỗi khi đọc file?
- [HELP] Java Swing
- bác nào xem hộ e lệnh nhập xuất vơi
- Thắc mắc về lỗi tìm kiếm tên miền và địa chỉ IP trong Netbean
- Cần giúp đỡ về Icon, Hide Systemtray và các vấn đề khác...
- Không kiểm tra được user và pass khi config sever
- Lỗi không thể tìm thấy haykhông thể tải main class
Với sự đa dạng và phong phú về mẫu mã và giá cả, choxeonline.vn hứa hẹn sẽ là địa chỉ tin cậy cho những ai đang tìm kiếm chiếc xe ô tô ưng ý. Từ những mẫu xe hạng sang đến những chiếc xe gia đình...
Khám Phá Đa Dạng Sản Phẩm Xe Ô Tô...