Java class name convention with respect to managed been usage in Primefaces

南楼画角 提交于 2019-12-23 03:25:17

问题


I am using Eclipse Indigo and whenever I create a new class starting with lower case then a warning is shown as displayed below (" Type name is discouraged. By convention, Java type names usually start with an uppercase letter").

Now in my xHTML / JSF file, if i try to access the class with first letter in caps then it is not accessible e-g;

'#{MyClass.variableName}' is NOT accessible nor the class constructor is called whereas '#{myClass.variableName}' works fine.

Note: class has an annotation "@ManagedBean"

Thanks

This is edited part: It only works if class is created with first letter as lower case "myClass" and in JSF file access with the same lower case "myClass"


回答1:


In order to follow the Java standard for class name I have used the following approach.

@ManagedBean(name="myClass")
public class MyClass {

}

previously due to JSF behaviour, I was using

@ManagedBean
public class myClass {

}

Please also share that what you do in such cases.

Thanks,

Asad




回答2:


Its the expected behavior

By default, the name associated with a bean is simply the lowercase form of its class name

You give your class a name with Capitalized Letter , like MyClass and accessing it from your xhtmls like this #{myClass.someVariable} (with a lower case prefix)

its not related to Primefaces , its the general approach in JSF



来源:https://stackoverflow.com/questions/12297006/java-class-name-convention-with-respect-to-managed-been-usage-in-primefaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!