我有selectOneMenu
<h:selectOneMenu id = "current" value = "#{helloBean.currentLanguage}">
<f:selectItems value="#{helloBean.categoryLanguages}"></f:selectItems>
<f:ajax render = "ccData"></f:ajax>
</h:selectOneMenu>
这是HelloBean
@ManagedBean(name="helloBean")
@SessionScoped
public class HelloBean implements Serializable {
private String currentLanguage;
public void setcurrentLanguage(String currentLanguage){
this.currentLanguage = currentLanguage;
}
}
设置currentLanguage时遇到问题。 Eclipse显示错误消息,#{helloBean.currentLanguage}
表达式无法设置。当我运行我的项目时,我收到错误
javax.servlet.ServletException: /hello.xhtml @19,74 value="#{helloBean.currentLanguage}": Property 'currentLanguage' not readable on type java.lang.String
答案 0 :(得分:2)
正如BalusC所指出的,Java是区分大小写的
所以当你写:value=#{helloBean.currentLanguage}
时,JSF希望你定义一个setter和该属性的getter(currentLanguage):
public void setCurrentLanguage(String language){
this.currentLanguage = language;//Or whatever
}
(注意当前的上部C。并添加一个吸气剂)
由于您使用的是Eclipse,因此请尝试自动生成类的访问方法。 (右键单击 - &gt; source - &gt;生成getter和setter)