[opencms-dev] Re ndering an element with a certain formatter programmatically

Fr3z roel.frison at redtree.be
Thu Nov 15 09:32:06 CET 2012


Thanks Tobias!

I managed to get the component rendered.

I used this piece of code:

<%
	CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
response);  
	CmsObject cmso = cms.getCmsObject();
	
	CmsADEConfigData adeConfig =
OpenCms.getADEManager().lookupConfiguration(cmso,cmso.getRequestContext().getRootUri());
	Locale locale = cmso.getRequestContext().getLocale();
	ServletRequest req = pageContext.getRequest();
    ServletResponse res = pageContext.getResponse();
	
	CmsJspStandardContextBean standardContext =
CmsJspStandardContextBean.getInstance(req);
	
	CmsUUID elementId = new CmsUUID("368253f9-280e-11e2-87b4-6f30f3c96804");
//fixed UUID for testing
	
	CmsUUID formatterId = new CmsUUID("ea80662f-0e03-11e2-8801-bd815a05da55");
//fixed UUID for testing
	
	String formatter =
"/system/modules/be.redtree.crelan.intranet.news/formatters/detail.jsp";

	CmsContainerElementBean containerelement = new
CmsContainerElementBean(elementId, formatterId, null, false);
	containerelement.initResource(cmso);
	standardContext.setElement(containerelement);
	
	CmsJspTagInclude.includeTagAction(pageContext,formatter,null,locale,false,
false, null,CmsRequestUtil.getAtrributeMap(req),req,res);
	
%>


It still lacks some error handling but it works. 

But now I have the following problem.

I added the jsp containing this code via a function provider element to a
page.
Now when I click the edit button, I can edit this function provider (normal
behaviour).
But I want to edit the element I programmatically added, and not edit the
function provider.

Is there a way to do this?

Greetings,

Roel


Tobias Herrmann wrote:
> 
> Hi Roel,
> 
> take a look at org.opencms.jsp.CmsJspTagContainer line 970 and following.
> Get an instance of CmsJspStandardContextBean like this:
> CmsJspStandardContextBean  standardContext =
> CmsJspStandardContextBean.getInstance(req);
> Also create an CmsContainerElementBean instance for the XMLContent
> resource you want to render and follow the example in the
> CmsJspTagContainer class.
> 
> Greetings, Tobias
> 
> --
> 
> Alkacon Software GmbH - The OpenCms Experts
> 
> http://www.alkacon.com
> http://www.opencms.org
> 
> Am 14.11.2012 15:43, schrieb Fr3z:
>> I have the UUID of an element (fe a news item), so I can acces its entire
>> xmlcontent.
>>
>> Now, is there a way to programmatically render this element in a jsp with
>> a
>> formatter of my choice instead of copying the code of the formatter in
>> this
>> jsp?
>>
>> I was trying via:
>>
>> <%
>> 	
>> 	CmsUUID elementId = new CmsUUID("368253f9-280e-11e2-87b4-6f30f3c96804");
>> //hardcoded UUID for testing purposes
>> 	
>> 	CmsResource formatter =
>> cms.readResource("/system/modules/be.redtree.crelan.intranet.news/formatters/detail.jsp");
>> 	CmsUUID formatterId = formatter.getStructureId();
>>
>> 	CmsContainerElementBean containerelement = new
>> CmsContainerElementBean(elementId, formatterId, null, false);
>> %>
>>
>> But I can't seem to get any further.
>>
>> Actually I'm looking for some kind of method that does this:
>> render(XMLcontent,formatter) and then displays it correctly.
>>
>> Anyone has any advice, help, manual about this?
>>
>> Kind regards,
>>
>> Roel Frison
> 
> _______________________________________________
> 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/cgi-bin/mailman/listinfo/opencms-dev
> 
> 
> 
> 
> 
-- 
View this message in context: http://old.nabble.com/Rendering-an-element-with-a-certain-formatter-programmatically-tp34678886p34682637.html
Sent from the OpenCMS - Dev mailing list archive at Nabble.com.




More information about the opencms-dev mailing list