[opencms-dev] requestContext cannot be resolved

Paoletti Corrado c.paoletti at fineco.it
Fri Apr 10 14:51:15 CEST 2015


Hi Paul,
your easiest solution works and I updated my code. Thanks.

It would be nice if


http://www.opencms-wiki.org/wiki/Read_a_property_of_an_arbitrary_CmsResource

would have updated with the code in this thread.

Best regards,

Corrado

From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Paul-Inge Flakstad
Sent: venerdì 10 aprile 2015 13:39
To: The OpenCms mailing list
Subject: Re: [opencms-dev] requestContext cannot be resolved

Hi Corrado,

The reason why you always get "prop has value null" is because you expect this to work:
if (myprop != null) // wrong way
It won't, because getPropertyObject will not return null in your case. It might however return a *null property* - which you can test it like this:
if (!myprop.isNullProperty()) // right way

But this aside, there is an easier way. You can just do like this:
<%
String prop = "";

CmsJspActionElement cmsAction = new CmsJspActionElement(pageContext, request, response);
CmsObject cmsObject = cmsAction.getCmsObject();

try {
   // get the property value, or an empty string if no property value is set
    prop = cmsObject.readPropertyObject(cmsAction.getRequestContext().getUri(), "cosa", false).getValue("");  // note the empty string in getValue
} catch ( CmsException exc ) {}
// prop is now either the set property value, or an empty string
%>

Cheers,
Paul

From: opencms-dev-bounces at opencms.org<mailto:opencms-dev-bounces at opencms.org> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Paoletti Corrado
Sent: 10. april 2015 11:32
To: The OpenCms mailing list
Subject: Re: [opencms-dev] requestContext cannot be resolved

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" %<mailto:%25 at taglib%20prefix=%22cms%22%20uri=%22http://www.opencms.org/taglib/cms%22%20%25>>

<%
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> [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/43f7f921/attachment.htm>


More information about the opencms-dev mailing list