在jsf中找不到属性'isPermutation'

时间:2015-03-19 19:27:03

标签: jsf jsf-2 primefaces

我正在尝试从xhtml页面为bean设置一个值。但是每次运行页面时都会显示我找不到属性的错误。我已经在bean中添加了属性。我有清洁&多次构建项目。但是什么都没有用,请帮助我。

 package com.loteria.controller;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


@SuppressWarnings("serial")
@ManagedBean(name="userDraw")
@RequestScoped
public class UserDrawController implements Serializable {

    boolean isPermutation;
    boolean isCombination;
    boolean isBoth;
    long per_amount;
    long per_num;
    long com_num;
    long com_amount;
    public boolean isPermutation() {
        return isPermutation;
    }
    public void setPermutation(boolean isPermutation) {
        this.isPermutation = isPermutation;
    }
    public boolean isCombination() {
        return isCombination;
    }
    public void setCombination(boolean isCombination) {
        this.isCombination = isCombination;
    }
    public boolean isBoth() {
        return isBoth;
    }
    public void setBoth(boolean isBoth) {
        this.isBoth = isBoth;
    }
    public long getPer_amount() {
        return per_amount;
    }
    public void setPer_amount(long per_amount) {
        this.per_amount = per_amount;
    }
    public long getPer_num() {
        return per_num;
    }
    public void setPer_num(long per_num) {
        this.per_num = per_num;
    }
    public long getCom_num() {
        return com_num;
    }
    public void setCom_num(long com_num) {
        this.com_num = com_num;
    }
    public long getCom_amount() {
        return com_amount;
    }
    public void setCom_amount(long com_amount) {
        this.com_amount = com_amount;
    }
    public void onChange()
    {
        System.out.print("Per is"+isPermutation);
        System.out.print("com is"+isCombination);

    }

}

XHTML

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<h:head>
    <title><ui:insert name="title">Loteria-Play Smart</ui:insert></title>
    <link rel="stylesheet" href="css/style.css" media="screen" type="text/css" />
    <script>
    function tb_enableDisable()
    {
        alert("heoo");
         document.getElementById('play_form:txt_per').disabled= true;
    }
</script>

</h:head>

<h:body>

    <div class="home-card">

        <div id="home-top">
            <h:form>
                <p:outputLabel style="color:white;padding-right:8px">Welcome</p:outputLabel>
                <p:outputLabel value="#{loginController.email}"></p:outputLabel>
                <p:commandLink action="#{loginController.logout}" value="Logout" styleClass="logout"></p:commandLink>
            </h:form>
        </div>
        <div id="play-center">
            <h:form id="play_form">
            <p:inputText value="#{userDraw.per_num}"></p:inputText>
                <p:outputLabel>What you want to play?</p:outputLabel>
                    <div style="margin-top: 10px">
                        <h:panelGrid columns="6" cellpadding="2" cellspacing="5"  style="margin:0 auto">
                            <p:selectBooleanCheckbox value="#{userDraw.isPermutation}">
                            <p:ajax update="play_form" listener="#{userDraw.onChange}"></p:ajax>
                            </p:selectBooleanCheckbox>
                            <h:outputText value="Permutation:" />

                            <p:selectBooleanCheckbox value="#{userDraw.isCombination}">
                            <p:ajax update="play_form" listener="#{userDrawDataController.onChange}"></p:ajax>
                            </p:selectBooleanCheckbox>
                            <h:outputText value="Combination:" />

                            <p:selectBooleanCheckbox value="#{userDraw.isBoth}" >
                            <p:ajax update="play_form" listener="#{userDraw.onChange}"></p:ajax>
                            </p:selectBooleanCheckbox>
                            <h:outputText value="Both:" />
                        </h:panelGrid>

                    </div>
                    <div style="margin-top:30px">
                    <h:panelGrid columns="1" cellpadding="2" cellspacing="2">
                        <p:outputLabel>Permuation:</p:outputLabel>
                            <h:panelGrid columns="2" cellpadding="2" cellspacing="2">
                            <p:inputText id="txt_per" placeholder="Permutation amount:" disabled="#{userDraw.isPermutation}"></p:inputText>
                            <p:inputText id="txt_pnum" placeholder="Number" disabled="#{userDraw.isPermutation}"></p:inputText>
                            <p:message for="txt_per"></p:message>
                            <p:message for="txt_pnum"></p:message>
                            </h:panelGrid>
                    </h:panelGrid>
                    <h:panelGrid columns="1" cellpadding="2" cellspacing="2">
                        <p:outputLabel>Combination:</p:outputLabel>
                            <h:panelGrid columns="2" cellpadding="2" cellspacing="2">
                            <p:inputText id="txt_comb" placeholder="Permutation amount:" disabled="#{userDraw.isCombination}"></p:inputText>
                            <p:inputText id="txt_cnum" placeholder="Number " disabled="#{userDraw.isCombination}"></p:inputText>
                            <p:message for="txt_comb"></p:message>
                            <p:message for="txt_cnum"></p:message>
                            </h:panelGrid>
                    </h:panelGrid>

                    </div>

                <h:panelGrid columns="2" cellpadding="5" cellspacing="5"
                    style="margin:0 auto;">


                    <p:commandButton value="Enter" style="width:100px"></p:commandButton>
                    <p:commandButton value="Cancel" style="width:100px"></p:commandButton>

                </h:panelGrid>

            </h:form>

        </div>






    </div>
</h:body>

</html>

1 个答案:

答案 0 :(得分:3)

当您的boolean属性命名为isPermutation时,getter应该被命名为isIsPermutation()

如果您将属性重命名为permutation,则可以保留名为isPermutation()的getter。

另请注意,如果您的属性类型设置为Boolean(并且属性名称为isPermutation),则此getter前缀不会起作用。在这种情况下,getter必须命名为getIsPermutation()

总结:

  • boolean属性的getter应以is开头。
  • Boolean(以及Object的其他子类型)的getter应以get开头。
  • 无论前缀如何,getter名称的后缀都应该是属性名称的UpperCamelCased版本。

更多信息: