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:
- Code java mở file .exe
- Lỗi comsume web service
- Danh sách liên kết trong java
- Hỏi về mảng các đối tượng trong Java?
- Thắc mắc Java script
- Trợ giúp webservice trong java ????
- Thắc mắc về GUI
- Lỗi Giao diện giải phương trình bậc nhất
- Cây tìm kiếm nhị phân
- thay đổi độ rộng cột-hàng trong table của HTML bằng javascript
Hướng dẫn vui nhộn về phương tiện nong lỗ đít Thuốc giãn hậu môn nghe có vẻ đáng sợ, nhưng đừng sợ! Hướng dẫn này sẽ đưa bạn qua hành trình hích khi dùng dụng cụ làm giãn lỗ đít, khiến nó trở...
Hướng dẫn vui nhộn về sản phẩm làm...