[opencms-dev] Passing a value from one jsp to another
Jonathan Woods
jonathan.woods at scintillance.com
Thu Sep 21 16:48:30 CEST 2006
Maria -
You can store state in CmsRequestContext using its method
setAttribute(String key, Object value). An instance of CmsRequestContext -
of which there is one per user-initiated request - is available from a
method on CmsObject. Warning: as a design pattern, try to avoid storing
lots of different kinds of objects in the request context, because you run
into all sorts of problems with hard-coded assumptions about the type of
each. I ended up implementing my own single class to store
application-specific state, and storing only this one in the request
context, keyed by a single String value:
// In JSP 1:
final CmsJspActionAlement cmsJspActionElement = new CmsJspActionElement();
cmsJspActionElement.init(pageContext, request, response); // standard JSP
symbols
final CmsObject cmsObject = cmsJspActionElement.getCmsObject();
final CmsRequestContext cmsRequestContext = cmsObject.getRequestContext();
final ApplicationRequestState appState = new ApplicationRequestState(...);
// do stuff to set up appState here.
cmsRequestContext.setAttribute(ApplicationConstants.APP_STATE_KEY_WHICH_IS_A
NYTHING_YOU_LIKE, appState);
...
// In JSP 2:
final CmsJspActionAlement cmsJspActionElement = new CmsJspActionElement();
cmsJspActionElement.init(pageContext, request, response);
final CmsObject cmsObject = cmsJspActionElement.getCmsObject();
final CmsRequestContext cmsRequestContext = cmsObject.getRequestContext();
final ApplicationRequestState appState = (ApplicationRequestState)
cmsRequestContext.get(ApplicationConstants.APP_STATE_KEY_WHICH_IS_ANYTHING_Y
OU_LIKE);
// Now do stuff using the app state you set up in the earlier JSP.
Jon
-----Original Message-----
From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of
maria.freixes_graells at alcatel.es
Sent: 21 September 2006 12:09
To: opencms-dev at opencms.org
Subject: [opencms-dev] Passing a value from one jsp to another
Hello Everybody!!
I've the following form in one of my jsp file, in order to select a folder
from the OpenCms, but now, I would like to pass the folder selected to
another file jsp, and I've trying to do it but I don't know the good way to
do it. Any idea about the code to add to my first jsp where I have the form,
and evenmore, what I would add to the other jsp in order than could receive
the folder selected?
Many thanks and best regards,
Maria
<form name="NEU" class="nomargin" onsubmit="pasteLink();">
<table border="0" cellspacing="0" cellpadding="4" width="100%">
<tr>
<td style="white-space: nowrap;"><%=
wp.key(org.opencms.workplace.editors.Messages.GUI_INPUT_LINKTO_0) %>:</td>
<td class="maxwidth">
<input type="text" name="neulink"
class="maxwidth" value="" onchange="checkLinkUrl();" />
</td>
<th>Select a directory to start searching</th>
<td><a href="javascript:openTreeWin('NEU',
'neulink', document);"><img src="<%= CmsWorkplace.getSkinUri()
%>filetypes/folder.gif" border="0" alt="<%=
wp.key(org.opencms.workplace.editors.Messages.GUI_LABEL_SELECTFOLDER_0)%>"><
/a></td>
</tr>
</table>
<%= wp.dialogContentEnd() %>
<%= wp.dialogButtonsOkCancel(null, "onclick=\"window.close();\"") %> </form>
_______________________________________________
This mail is sent to you from the opencms-dev mailing list To change your
list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/mailman/listinfo/opencms-dev
More information about the opencms-dev
mailing list