[opencms-dev] How to access own Java Class via JSP in OpenCMS 5 RC2

Alexander Kandzior alex at opencms.org
Fri Apr 4 10:02:05 CEST 2003


Just some quick things on that from my side:

Get an instance from the CmsObject like this on your JSP page:

<%
	
// initialise Cms Action Element
com.opencms.flex.jsp.CmsJspActionElement cms = new
com.opencms.flex.jsp.CmsJspActionElement(pageContext, request,
response);
    
// collect the CmsObject required to access the OpenCms VFS 
com.opencms.file.CmsObject cmsObject = cms.getCmsObject();	

%>

Now create an instance of your Bean. Your Bean should then have a method
like "setCmsObject(CmsObject cms)". Use this method to pass the OpenCms
object to the bean. Do stuff with the CmsObject in your bean.

I do not recommend storing the CmsObject in the session. Reason is that
that CmsObject also contains the credentials of the user who has logged
on to OpenCms (user is Guest if he is not logged on). This also means
that you will have only accesss to resources that user Guest can access.
Make sure your permissions are set accordingly. Storing the OpenCms
object in the context is o.k. as long as it is the page or request
context. 

Best Regards,
Alex.

Alexander Kandzior
Alkacon Software - The OpenCms Experts
http://www.alkacon.com

> -----Original Message-----
> From: owner-opencms-dev at www.opencms.org 
> [mailto:owner-opencms-dev at www.opencms.org] On Behalf Of Marcus Redeker
> Sent: Friday, April 04, 2003 12:30 AM
> To: opencms-dev at www.opencms.org
> Subject: RE: [opencms-dev] How to access own Java Class via 
> JSP in OpenCMS 5 RC2
> 
> 
> You can get access to the CmsObject from your JSP request 
> object. Look into the nav-demo.jsp Once you have the 
> CmsObject you can give it into your bean class using a normal 
> setter. It should also be possible to store the CmsObject 
> within the Web-Session or even the Context. But I am not sure 
> about that. Maybe Alexander knows about that.
> 
> Cheers,
> --Marcus
> 
> 
> 
> > -----Original Message-----
> > From: opencms-dev-owner at www.opencms.org
> > [mailto:opencms-dev-owner at www.opencms.org] On Behalf Of 
> > ambiesense at gmx.de
> > Sent: Thursday, April 03, 2003 8:08 PM
> > To: opencms-dev at www.opencms.org
> > Subject: RE: [opencms-dev] How to access own Java Class via 
> > JSP in OpenCMS 5 RC2
> > 
> > 
> > Hello,
> > 
> > thanks for your quick answer :) This sounds good. I have had
> > a look to the usebean Tag. However this bean need to get 
> > access to the OpenCMS instance. This seems to be a problem. I 
> > have used that code before triggered by a content template. 
> > Every time a website, made from this OpenCMS content 
> > template, was accessed. My class overwrites that method:
> > 
> > public byte[] getContent(CmsObject cms, String templateFile,
> > String elementName, 
> >                              Hashtable parameters, String 
> > templateSelector) throws CmsException {
> > 
> > so I got access to CmsObject. With this CmsObject I could
> > access i.e. Files in the VFS or users in OpenCMS. 
> > 
> > How can I do this with the JSP approach?
> > 
> > Any help would be highly appreciated!
> > 
> > Cheers,
> > Ralf
> > 
> > > Hi,
> > > 
> > > this is no problem. You just have to make sure that the
> > OpenCMS webapp
> > > is seeing your class. Either put it into the  opencms.jar or under
> > > WEB-INF/classes. If you just want to use the class as a 
> > bean you can
> > > use the "useBean" - Tag. For that you don't need to write your own
> > > tags.
> > > 
> > > --Marcus
> > > 
> > > > -----Original Message-----
> > > > From: opencms-dev-owner at www.opencms.org 
> > > > [mailto:opencms-dev-owner at www.opencms.org] On Behalf Of 
> > > > ambiesense at gmx.de
> > > > Sent: Thursday, April 03, 2003 6:23 PM
> > > > To: opencms-dev at www.opencms.org
> > > > Subject: [opencms-dev] How to access own Java Class via JSP
> > > > in OpenCMS 5 RC2
> > > > 
> > > > 
> > > > Hi,
> > > > 
> > > > I followed the advice of Tim Howland and want to use 
> JSP and JSTL 
> > > > for dynamic page generation. I am planning to develop an Hello 
> > > > World example:
> > > > 
> > > > I want to have a JSP page with a very basic form (textfield and 
> > > > submit button).  The user enters his name  in the 
> textfield (i.e. 
> > > > Bob) and press the submit button. The word get somehow 
> transported 
> > > > to another JSP page which calles a method in my own Java class 
> > > > with the word as parameter. The Java class simply returns the 
> > > > input (Echo method). This result should be displayed in 
> this JSP 
> > > > so it finally produces the output: "Hello World Bob".
> > > > 
> > > > Is this generally possible? Will I need to develop my 
> own TLD file 
> > > > declaring the tags I want to be able to use? Does somebody has 
> > > > already developed some JSP which access a own
> > > > (non-OpenCMS) Java class (i.e. a Java Bean) ?
> > > > 
> > > > Thanks in advance,
> > > > Ralf
> > > > 
> > > > --
> > > > +++ GMX - Mail, Messaging & more  http://www.gmx.net +++
> > > > Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!
> > > > 
> > > > 
> > > 
> > > 
> > 
> > --
> > +++ GMX - Mail, Messaging & more  http://www.gmx.net +++
> > Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!
> > 
> > 
> 
> 
> 
> 




More information about the opencms-dev mailing list