根据我的一些价值观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: #{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.selectedPaper
,printerSettings.selectedPaperValue
和printerSettings.timeToPrint
,它们下面有这些黄线,奇怪的是它从豆中提取信息,所以我得到一个默认值2000的打印时间和菜单显示三个选项,为什么这样做?有什么不对吗?
这是我的faces-config
<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位下面得到一条黄线,表示在初始化期间使用非静态变量
答案 0 :(得分:1)
我认为您收到警告"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 + name开始。
JSF使用getter和setter来访问POJO的属性。