Skip to Content
author's profile photo Former Member
Former Member

Explain the codes

hi all,

When we create JSP dynpage along with a bean class and give its scope as application the following codes are created from the template

<b>IPortalComponentProfile profile = ((IPortalComponentRequest)getRequest()).getComponentContext().getProfile();

Object o = profile.getValue("Bean");

if(o==null || !(o instanceof newBean)){

Bean = new newBean();

profile.putValue("Bean",Bean);

} else {

Bean = (newBean) o;</b>

Could anyone explain me what it really does which would help me and the beginners in EP.

regards

Ganesh.N

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Nov 18, 2005 at 02:00 PM

    I can give it a go 😊

    The first line gets the IPortalComponentProfile object for that component. This is stored in the IPortalComponentContext object, which is in turn stored in the IPortalComponentRequest object.

    The second line basically retrieves the object that is stored in the profile. This object is the Bean object that has been stored in the IPortalComponentProfile as part of the DynPage class.

    The third line basically checks to see whether a valid object has been retrieved from the IPortalComponentProfile. This is done by checking to see whether the variable 'o' is null. If it is not null, it then checks to see whether the object is an 'instanceof' newBean. This means that the object has been created as an instance of the newBean class (newBean.java).

    If the object 'o' is null (not created yet) or is not an instance of the newBean class (a different class stored with under the same name), then a new newBean object is instantiated and then stored in the IPortalComponentProfile.

    If the object 'o' is not null (has been created) and is an instance of newBean (it is the correct class), this object 'o' is then cast into the newBean class. Because 'o' is already an instance of newBean, this casting means that you can then use the methods associated with this newBean class.

    One of the reasons for storing the newBean class is so that it can be retrieved in the JSP page or in the DynPage and is a way of maintaining state of the application.

    I would, however, point out that it is not a good place to store the beans now as it will sometimes get garbage collected ending up with NullPointerExceptions. The way around this would be to store/retrieve the bean from the IPortalComponentSession instead, you can do this by

    IPortalComponentSession session = request.getComponentSession();

    //Store value

    session.putValue("Bean", Bean);

    //Retrieve value

    session.getValue("Bean");

    I hope this helps a little 😊

    Darrell

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 18, 2005 at 02:07 PM

    Hi Ganesh,

    This is how it works:

    IPortalComponent is the portal component you create. First the instance of the Request is brought. From the request we get the context of the iView. The context of the iView would contain the profile object that is fetched using the 'getValue' method.

    Here the profile object is given the instance of the bean.

    Naveen.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.