I wowould like to do the following but I cannot access the arraylist
The JSP. cocould anyone help?
1. Use the doview ()-method to store an arraylist IN THE SESSION
========================================================== ======================================
Doview (){
....
Mysimplebean my1 = new mysimplebean ();
My1.setmessage ("test1 ");
Mysimplebean my2 = new mysimplebean ();
My2.setmessage ("Test2 ");
Arraylist mysimplebeans = new arraylist ();
Mysimplebeans. Add (my1 );
Mysimplebeans. Add (my2 );
Request. getportletsession (). setattribute ("Jens", mysimplebeans,
Portletsession. portlet_scope );
....
}
2. Access this bean from the JSP (this does not work)
========================================================== ======================================
<% @ Page session = "true" contenttype = "text/html"
Import ="Java . Util. *, javax. Portlet .*,
Com. Linde. Portal . Application. Domino. Pike. navigatio N. * "%>
<% @ Taglib uri = "http://java.sun.com/portlet" prefix = "Portlet" %>
<% @ Taglib uri = "http://java.sun.com/jstl/core" prefix = "C" %>
<% @ Taglib uri = "http://java.sun.com/jstl/fmt" prefix = "FMT" %>
<Portlet: defineobjects/>
<JSP: usebean id = "Jens"
Class = "com. Linde. Portal. application. Domino. Pike. Na vigation. mysimplebean"
Scope = "session"> </jsp: usebean>
<Table>
<C: foreach Var = "mysimplebean" items = "$ {Jens}">
<Tr>
<TD> <cut value = "$ {mysimplebean. Message}"/> </TD>
</Tr>
</C: foreach>
</Table>
3. This code works...
========================================================== ======================================
....
<%
Arraylist jens2 = NULL;
Try {
Portletsession mysession = renderrequest. getportletsession ();
Jens2 = (arraylist) mysession. getattribute ("Jens ",
Portletsession. portlet_scope );}
Catch (exception e ){
E. printstacktrace (system. Out );
} %>
<%
If (jens2! = NULL ){
%>
<% = (Mysimplebean) jens2.get (0). getmessage () %>
<%} Else {%>
<% = "Empty" %>
<% }%>
==================
Posts: N/ |
Re: JSP: usebean-access arraylist containing beans? I looked at it once more and noticed the following which seems to be Related to the problem. I can access the attribute "jens2" in the JSP But I cannot access the attribute "jens3". There will be an empty String cerated for "jens3". Can you explain me why? Thanks! Portlet ========================================================== ====================================== Doview (){... Request. setattribute ("jens2", "request Hello World "); Request. getportletsession (). setattribute ("jens3", "session hello World "); ....} JSP ========================================================== ====================================== <JSP: usebean id = "jens2" class = "Java. Lang. String" Scope = "request"> </jsp: usebean> <JSP: usebean id = "jens3" class = "Java. Lang. String" Scope = "session"> </jsp: usebean> .... |