You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dave Belfer-Shevett <db...@homeport.org> on 2008/07/13 22:47:38 UTC

Referring to Properties object via OGNL?

I have a situateion where I'm loading application specific settings via a 
Properties object on initialization.  I'm storing the Properties object up 
into the ApplicationMap (heck it could be in the SessionMap, I'm easy), 
but i can't seem to switch JSP behaviour based on information in the 
Properties map.

I'm wondering if this is because Properties isn't exactly a HashMap, so 
the #attr.mapname.somekey isn't working.

If I have a Properties object called 'props' in the SessionMap (or 
anywhere on the stack actually), I should be able to get to it via #attr - 
what's the proper syntax?

Java-wise, it's

Property p = new Properties;
String value = p.getProperty("somekey")

but naturally I don't want to do this in a scriptlet.

Help?

-- 
-------------------.--------.-------------------------------.
Dave Belfer-Shevett \ KB1FWR \ JID: dbs@jabber.stonekeep.com \
blog:planet-geek.com >--------'-----------------------------------.
dbs@homeport.org    / Things you'll hear if you have a Klingon on  \
-------------------<   your development team: 3) "This code is a    |
                    |       piece of crap! You have no honor!"       |
                     \______________________________________________/


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Referring to Properties object via OGNL?

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Dave Belfer-Shevett wrote:
>
>
> That fixed it.  Is there a chance we can update the 'collections' page in the 
> struts docs to give information like this?  
>
>   
Great!  Can you please post a comment to the relevant docs page so one 
of the developers remembers to update it?

You're also welcome to contribute to the documentation: 
http://struts.apache.org/helping.html#documentation


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Referring to Properties object via OGNL?

Posted by Dave Belfer-Shevett <db...@homeport.org>.
On Monday 14 July 2008 00:30:19 Jeromy Evans wrote:
> Dave Belfer-Shevett wrote:
> > In my JSP, I have:
> > Preferred cid is <s:property value="#attr.properties[preferredcid]"/><br>
>
> This expression reads "evaluate perferredcid, then get the value of
> #attr.properties[evalresult]".
>
> I expect you want. <s:property value="#attr.properties['preferredcid']"/>
>
> so it uses the literal string 'preferredcid' instead of evaluating it.
>
> Please let me know if that fixes it.  OGNL doesn't provide much useful
> feedback for cases like these.

That fixed it.  Is there a chance we can update the 'collections' page in the 
struts docs to give information like this?  

Thanks again.

	-d

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Referring to Properties object via OGNL?

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Dave Belfer-Shevett wrote:
>
>
> In my JSP, I have:
> Preferred cid is <s:property value="#attr.properties[preferredcid]"/><br>
>
> Which, when rendered:
> Pddreferred cid is
>
> (with nothing after it)

This expression reads "evaluate perferredcid, then get the value of 
#attr.properties[evalresult]".

I expect you want. <s:property value="#attr.properties['preferredcid']"/>

so it uses the literal string 'preferredcid' instead of evaluating it.

Please let me know if that fixes it.  OGNL doesn't provide much useful 
feedback for cases like these.






---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Referring to Properties object via OGNL?

Posted by Dave Belfer-Shevett <db...@homeport.org>.
On Sun, 13 Jul 2008, Gabriel Belingueres wrote:
> Properties implements the Map interface, so AFAIK, it should work
> accessing it as a Map.
>
> Did you tried #attr.mapname[somekey]?

Yes...

I have an interceptor that does:

applicationMap = invocation.getInvocationContext().getApplication();
applicationMap.put("properties",props);
logger.debug("Props loaded: " + props.toString());

(when run, this sez:
2008-07-12 23:18:37,828 DEBUG 
com.stonekeep.congo.interceptors.DBInterceptor:138 - Props loaded: 
{preferredcid=2008}

In my JSP, I have:
Preferred cid is <s:property value="#attr.properties[preferredcid]"/><br>

Which, when rendered:
Pddreferred cid is

(with nothing after it)

The entire interceptor that is loading up the properties file and 
publishing it into the ApplicationMap is here:

http://pastebin.stonekeep.com/4949

I may be missing something painfully obvious, but... help?

 	-d

-- 
-------------------.--------.-------------------------------.
Dave Belfer-Shevett \ KB1FWR \ JID: dbs@jabber.stonekeep.com \
blog:planet-geek.com >--------'-----------------------------------.
dbs@homeport.org    /   Windows98 Err#021 - Error Parsing Error    \
-------------------<        List; Please Wait For Next Error        |
                     \______________________________________________/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Referring to Properties object via OGNL?

Posted by Gabriel Belingueres <be...@gmail.com>.
Properties implements the Map interface, so AFAIK, it should work
accessing it as a Map.

Did you tried #attr.mapname[somekey]?

2008/7/13 Dave Belfer-Shevett <db...@homeport.org>:
> I have a situateion where I'm loading application specific settings via a
> Properties object on initialization.  I'm storing the Properties object up
> into the ApplicationMap (heck it could be in the SessionMap, I'm easy), but
> i can't seem to switch JSP behaviour based on information in the Properties
> map.
>
> I'm wondering if this is because Properties isn't exactly a HashMap, so the
> #attr.mapname.somekey isn't working.
>
> If I have a Properties object called 'props' in the SessionMap (or anywhere
> on the stack actually), I should be able to get to it via #attr - what's the
> proper syntax?
>
> Java-wise, it's
>
> Property p = new Properties;
> String value = p.getProperty("somekey")
>
> but naturally I don't want to do this in a scriptlet.
>
> Help?
>
> --
> -------------------.--------.-------------------------------.
> Dave Belfer-Shevett \ KB1FWR \ JID: dbs@jabber.stonekeep.com \
> blog:planet-geek.com >--------'-----------------------------------.
> dbs@homeport.org    / Things you'll hear if you have a Klingon on  \
> -------------------<   your development team: 3) "This code is a    |
>                   |       piece of crap! You have no honor!"       |
>                    \______________________________________________/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Referring to Properties object via OGNL?

Posted by Dave Belfer-Shevett <db...@homeport.org>.
On Sun, 13 Jul 2008, Martin Gainty wrote:
> access it with
> <%
> ValueStack stack = getStack();
> stack.findValue("#attr.someKey");
> %>
> http://www.docjar.com/docs/api/java/util/Stack.html
>
> where you put the value.. HashSet,HashMap or Property is up to you..

Doesn't this violate the 'scriptlets are bad' concept?

 	-dbs

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org