[opencms-dev] requestContext cannot be resolved
Paoletti Corrado
c.paoletti at fineco.it
Fri Apr 10 11:32:13 CEST 2015
Hi,
it works! Thank you very much.
Despite last two rows in suggested article I replaced them with:
String prop = "";
try {
prop = cmsObject.readPropertyObject(cmsAction.getRequestContext().getUri(), "cosa", false).getValue();
}
catch ( CmsException exc ) {}
if ( CmsStringUtil.isEmptyOrWhitespaceOnly( prop ) ) {
prop = "";
}
I think it isn't the best solution (I'm not Java wizard!) but I made this change because if I use:
CmsProperty myprop = cmsObject.readPropertyObject(cmsAction.getRequestContext().getUri(), "cosa", false);
prop = (myprop != null) ? myprop.getValue() : "";
and cosa property exists but has not value and test prop value:
if ( prop == "" ) {
out.println("prop has not value");
} else {
out.println("prop has value " + prop);
}
I always have "prop has value null" and I don't understand why.
For further reference the complete code is:
<%@ page import="org.opencms.jsp.CmsJspActionElement,
org.opencms.file.CmsObject,
org.opencms.file.CmsResource,
org.opencms.file.CmsProperty,
org.opencms.main.CmsException,
org.opencms.util.CmsStringUtil,
org.opencms.main.OpenCms" session="true" %>
<%@taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%
String prop = "";
CmsJspActionElement cmsAction = new CmsJspActionElement(pageContext, request, response);
CmsObject cmsObject = cmsAction.getCmsObject();
try {
prop = cmsObject.readPropertyObject(cmsAction.getRequestContext().getUri(), "cosa", false).getValue();
}
catch ( CmsException exc ) {}
if ( CmsStringUtil.isEmptyOrWhitespaceOnly( prop ) ) {
prop = "";
}
%>
Corrado
From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Antonio Cordeddu
Sent: giovedì 9 aprile 2015 18:57
To: The OpenCms mailing list
Subject: Re: [opencms-dev] requestContext cannot be resolved
Hi Corrado,
try this:
CmsProperty titleProp = cmsObject.readPropertyObject (cmsAction.getRequestContext().getUri(), "Title", false);
Best regards
Antonio Cordeddu
On 09/04/2015 17:54, Paoletti Corrado wrote:
Hi all,
in my template I'd like to read a custom property.
Reading article:
http://www.opencms-wiki.org/wiki/Read_a_property_of_an_arbitrary_CmsResource
I copied and pasted code suggested but when I click over a html based on the template I get the error:
Unable to compile class for JSP:
An error occurred at line: 15 in the jsp file: [my jsp file]
requestContext cannot be resolved
I don't know what i'm doing wrong.
Thank you.
_______________________________________________
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
_______________________________________________
Coranto informatica di Antonio Cordeddu
Via Torricelli, 9 09047 Selargius (CA) - Italy
antoniocordeddu at coranto.it<mailto:antoniocordeddu at coranto.it>
http://www.coranto.it
_______________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20150410/6aeafaf5/attachment.htm>
More information about the opencms-dev
mailing list