问题
I try to add annotations in a Java class to take the bean in XPages. But when I try this:
@ManagedBean(name="photoBean")
@SessionScoped
public class PhotoBean implements Serializable {
private static final long serialVersionUID = -6839844250507324282L;
private String idPhoto;
private String nomPhoto;
public String getIdPhoto() {
return idPhoto;
}
public void setIdPhoto(String idPhoto) {
this.idPhoto = idPhoto;
}
}
it doesn't compile:
@ManagedBean(name="photoBean")
@SessionScoped
Is there special code to do that? Or is it only for Java EE and not for Lotus? Notes says to create the annotations.
回答1:
As they said, no, it is not possible to use the annotations in Xpages. DARN! Yeah, i want them too. Anyway the way to go about registering your Beans is through the faces-config.xml file. (package explorer view, application/WebContent/WEB-INF/faces-config.xml) The XML would look like:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config>
<managed-bean>
<managed-bean-name>ErrWriter</managed-bean-name>
<managed-bean-class>de.hol.utils.errorHandling.ErrorWriter</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<!--AUTOGEN-START-BUILDER: Automatically generated by IBM Domino Designer. Do not modify.-->
<!--AUTOGEN-END-BUILDER: End of automatically generated section-->
</faces-config>
Happy Programming!
回答2:
Annotations for managed beans have been introduced after JSF 2.0. But XPages is based on JSF 1.1.
So you cannot use such annotations in XPages.
Update:
Make sure you have checked Jesse's blog entry:
https://frostillic.us/f.nsf/posts/a-quick--dirty--and-inefficient-%40managedbean-implementation-in-xpages
回答3:
Short answer: no
Long answer: the JSF implementation in XPages doesn't implement Java EE 6.0 and JSF 2.0 where annotations are defined. You need to edit your faces-config.xml to include a managed bean
来源:https://stackoverflow.com/questions/24800360/is-possible-to-add-annotation-managedbean-in-xpages