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:
- mong các bạn rãnh giúp mình với !
- phương thức ẩn hiện form trong java
- loi ve truyen tham so
- Thắc mắc về khi tính toán vượt quá giá trị lớn nhất của kiểu dữ liệu
- Học giao diện Java cơ bản như thế nào
- Cần tìm bài tập Java!
- không nhập xuất ma trận trong java được. Help
- kiểm tra chuỗi nhập vào có số âm hay không?
- Điểm mạnh của framework hibernate
- Cần giúp gửi dữ liệu tới nhiều sever
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...