1

在我的一些价值观下,我得到了黄线说unkown property values

<p:spinner min="1" max="50" value="#{printerSettings.p}" size ="1"> <!-- allows the user a choice of up to 50, this is more than enough for any situation, if needed this can be removed or raised -->
                        <p:ajax update="p"/>
                    </p:spinner>
                    <br></br>
                    <br></br>
                    <h:outputText value="Copies that will be printed: &nbsp; #{printerSettings.p}" id="p"/>
                    <br></br>
                    <br></br>


                    Double sided?: 

                    <br></br>
                    <br></br>

                    Paper Size : 
                    <h:selectOneMenu value="#{printerSettings.selectedPaper}">
                        <f:selectItems value="#{printerSettings.selectedPaperValue}" />
                    </h:selectOneMenu> 

                    <br></br>
                    <br></br>

                    What time would you like the printer to print out your work ?, please enter the minutes after midnight :  
                    <br></br>

                    <br></br>
                    <p:inputText id="timeToPrint" value="#{printerSettings.timeToPrint}" />
                    <br></br>

printerSettings.p工作得非常好,它们是printerSettings.selectedPaperprinterSettings.selectedPaperValue并且printerSettings.timeToPrint在它们下面有这些黄线,奇怪的是它从 bean 中提取信息,所以我得到一个默认值为 2000 的打印时间,菜单显示三个选项,为什么会这样这样做?有什么不对 ?

这是我的面孔配置

   <managed-bean>
        <managed-bean-name>printerSettings</managed-bean-name>
        <managed-bean-class>richard.fileupload.PrinterSettings</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>

这是我的豆子

public class PrinterSettings {

//@NotNull(message = "Please enter a time to print ")
    private int timeToPrint = 2000;
    private int p = 1; //sets default value
    private int time;
    public String selectedPaper = "A4"; // defualts to A4

    public int gettimeToPrint() {
        return (timeToPrint);
    }

    public void settimeToPrint(int timeToPrint1) {
        this.timeToPrint = timeToPrint1;
    }

    public int getP() {
        return (p);
    }

    public void setP(int p1) {
        this.p = p1;
    }

    public int gettime() {
        return (time);
    }

    public void settime(int time) {
        this.time = time;
    }

    public String getselectedPaper() {
        return selectedPaper;
    }
    private static Map<String, Object> paperValue;

    static {
        paperValue = new LinkedHashMap<String, Object>();
        paperValue.put("A5", "A5"); //right hand side is value, may need to change this later on to make compatable with the printers
        paperValue.put("A4", "A4");
        paperValue.put("A3", "A3");
    }

    public Map<String, Object> getselectedPaperValue() {
        return paperValue;
    }
}

我还注意到在 bean 中我在 paperValue.put 位下得到一条黄线,表示在初始化期间使用了非静态变量

4

1 回答 1

2

我认为您会"unknown property in value"因为 PrinterSettings bean 属性的错误 getter 和 setter 名称而收到警告。对于selectedPaper属性,getter 名称应为getSelectedPaper,而 setter 名称应为setSelectedPaper。对于selectedPaperValue属性,getter 名称应为getSelectedPaperValue,而 setter 名称应为setSelectedPaperValue。对于timeToPrint属性,getter 名称应为getTimeToPrint,setter 名称应为setTimeToPrint

setter 的名称应该从 set + 属性的名称开始,第一个大写字母。getter 的名称应该从 get + 属性的名称开始,第一个大写字母。

JSF 使用 getter 和 setter 来访问 POJO 的属性。

于 2013-02-10T10:13:53.327 回答