Is possible to add annotation @ManagedBean in XPages?

假装没事ソ 提交于 2019-12-11 04:58:21

问题


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

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