在JSF中提交按钮后,xhtml没有返回任何内容

时间:2015-10-14 06:47:49

标签: jsf managed-bean

我有简单的BMIclass,并尝试使用JSF接收输入并显示BMI类的结果。但点击提交按钮后,我的xhtml页面不会返回任何内容。 我的BMI课程:

Select * from Books where title like '%net%'

}

XHTML文件:

   public class BMI {
   private static int weight;
   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 () {

    double bmi;
    bmi = (double)(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;
}

控制器类:

    <h:body>
<h:form>
<p:panel id="panel" header="BMI Calculator" style="margin-bottom:10px;">
    <p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
    <h:panelGrid columns="2" cellpadding="5">
        <h:outputLabel for="weight" value="Weight(in lbs):" />
        <p:inputText id = "weight" value="#{bmiController.bmiBean.weight}" required="true" />

        <h:outputLabel for="height" value="Height(in inches):" />
        <p:inputText id = "height" value="#{bmiController.bmiBean.height}" required="true" />required="true" />


    </h:panelGrid>
</p:panel>

   <p:commandButton value="Calculator" update="panel" actionListener="#{bmiController.calculate}"/>

}

1 个答案:

答案 0 :(得分:0)

将你的#{BmiController.weight}更改为xhtml页面中的#{bmiController.weight}。

将所有BmiController替换为XHTML页面中的bmiController。