我正在关注jsf的一些基本教程,并在bean名称userData
@ManagedBean(name="userData", eager=true)
@SessionScoped
public class userData implements Serializable
{
private static final long serialVersionUID = 1L;
private String name;
private String password;
private String welcomeMessage;
private String selectedCountry = "United Kingdom";
private static Map<String, String> countries;
static
{
countries = new LinkedHashMap<String, String>();
countries.put("en", "United Kingdom");
countries.put("fr","French");
countries.put("de","Germany");
}
public void localeChanged(ValueChangeEvent e)
{
selectedCountry = e.getNewValue().toString();
}
public void setSelectedCountry(String selectedCountry)
{
this.selectedCountry = selectedCountry;
}
public String getSelectedCountry()
{
return selectedCountry;
}
public Map<String, String> getCountries()
{
return countries;
}
public void userData()
{
this.name = "Mario";
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public void setPassword(String password)
{
this.password = password;
}
public String getPassword()
{
return this.password;
}
public String login()
{
return "result";
}
public String getWelcomeMessage()
{
return "hello" + name;
}
}
在.xhtml页面的另一边我有一部分html代码如下:
<h:form>
<h1>
#{userData.selectedCountry}
</h1>
<h:selectOneMenu value="#{userData.selectedCountry}"
onchange="submit()"
valueChangeListener="#{userData.localeChanged}">
<f:selectItems value="#{userData.countries}"/>
</h:selectOneMenu>
<br/>
<h1>
Country Name :
<h:outputText id="country" value="#{userData.selectedCountry}"/>
</h1>
</h:form>
但是当我在服务器上执行页面时,会产生以下错误: useBeans.xhtml:在类型userData上找不到属性'selectedCountry'。 有谁可以请突出我做错了什么?
答案 0 :(得分:1)
在我的情况下,原因是因为我复制了一个包含serialVersionUID字段的类:
private static final long serialVersionUID = 5443351151396868724L;
所以我有两个不同的类和对象具有相同的serialVersionUID,这就是问题的线索。