on 10-23-2007 9:02 AM
Hi experts,
I am confused about the scope of bean in JspDynPage portal component.
According to documents in SDN:
- In JSP file, scope of bean are session, application, page, request. And SAP recommends us using session to store the bean.
I mean when we create a bean in jsp file, we assign it a scope. How about the scope of bean declared in JSPDynPage Class?
Could anyone clarify it for me?
Thanks.
Thanks all for your reply.
I just created a bean in doInitialization() and didn't assign it to any bean created in jsp, so the bean in jsp will be null.
Therefore I am wondering that how the bean created in doInitialization() knows which bean in <b>what jsp</b> to get the scope?
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
By default, when u create a JSPDynPage, it creates bean definition in JSP and declares that in JSPDynPage. Thus it knows the communcation between JSP and DynPage bean scope. If u remove that line also, u can find it out from portalapp.xml. The JSP and its corresp class name will be listed under components. Thus it knows which Jsp and scope of it.
Regards,
Harini S
Please close the thread if your question is answered
Hi Harini,
Thanks for your answer.
But in fact in portalapp.xml, I don't declare jsp file in portal component (JSPDynPage class). And I have two other examples:
1. If I have 1 jsp file in which there are 2 beans declared with 2 different scopes. One is session, one is application, and again in jspdynpage, I declare 2 beans in doInitialization(), and not assign to 2 beans in jsp. How do the beans in jspdynpage know their scope.
2. If there are two or more jsp file as output for one jspdynpage class, with each has a bean declared with different scope. How do the beans choose which scope?
Please help me clarify it.
Thanks.
Hi,
These answers are according to my understanding.
For ur first ques, as I already told, just decalring in JSPDynPage or declaring from JSP page alone will not work. The bean has to be created during JSPDynPage creation wizards itself and reference of this will be automatically done, though u remove the JSP lines from portal-app.xml. Thus only one bean will be handling data between DynPage and JSP. If u declare some other bean with different scopes which is not created with JSP, then it will not b visible to JSP anyway, whatever scope may be. Similarly, when u create some bean with JSP but declare some other bean in JSPDynPage, then the ones in JSPDynPage will not be visible too.. So it is one bean between one JSPDynPage and JSP. This bean can be used in multiple JSPs but has to be created from one JSP.
For ur second question, think u woud have got answers from first ques itself. The bean with scope defined during first JSPDynPage and JSP creation will work. If u try different scope in new JSP, it will return null. U will find data in that particular scope only.
Regards,
Harini S
Hi Kebab,
Scope is Where we can access something.
Session scope will be for the entire session of the user so u can access the attributes until the user session ends.(Probably this is the reason for sap recomanding this.)
If u r creating an instance of the bean in the JSPDynpage and making it available for session u can access it any where in other JSP pages until the session terminates.
Scope should be decidid by urself depending on ur requirement of availability.
To make the bean instance available to a scope just add it as an attribute to that scope.
Mr.Chowdary
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The bean created with the scope in JSP is initialized in JSPDynPage automatically in doInitialization() method. So these are same. So depending on the scope, bean is visible to the component (as mentioned in the above answer). In case, u r trying to declare some other bean in JSPDynPage, other than one created with JSP, then that is visible to the java classes only and not JSP. So the bean which is created with JSP is used to communicate with JSPDynPage and JSP.
Regards,
Harini S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi There !
The Scope can be Defined only in JSP and not in JSPDynPage Class.
In the JSPDynpage we can just access the Bean
How we access the Bean Depends on what scope it is defined in.
Page : pageContext object
Request : request object
session : PortalComponentSession object, from request.getSession()
application : PortalComponentContext object
Regards,
Rajendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.