You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pierre Thibaudeau <pi...@gmail.com> on 2008/07/13 22:43:11 UTC

[S2] action mapping with merely default action

With Struts1, if I wished to render a JSP page without bothering with the
machinery of an action (yet going through the filters/interceptors), I would
have an action mapping as follows:

        <action path="/home" forward="/static/home.jsp" />

With Struts2, in the same situation, I would do:

        <action name="home" class="com.opensymphony.xwork2.ActionSupport">
            <result>/static/home.jsp</result>
        </action>

This is a case where Struts2 is a lot wordier than Struts1.  (I have to do
this about 15 times, for the site's "static" pages...)

Is there a shorthand version?

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


Referring to Properties object via OGNL?

Posted by 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


Re: [S2] action mapping with merely default action

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
> 2008/7/13 Dave Newton <ne...@yahoo.com>:
>
>   
>> Again, this is if you're intent on using XML configuration.
>>
>>     

Dave didn't mention that if you're NOT intent on using XML 
configuration, then the CodeBehind plugin was created exactly for this 
purpose.

http://struts.apache.org/2.x/docs/codebehind-plugin.html


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


Re: [S2] action mapping with merely default action

Posted by Pierre Thibaudeau <pi...@gmail.com>.
Brilliant!  Thanks, Dave!

2008/7/13 Dave Newton <ne...@yahoo.com>:

> Depending on how your application is laid out you could also put a
> "catch-all" mapping at the end of your regular mappings, like so:
>
> <action name="*">
>  <result>/static/{1}.jsp</result>
> </action>
>
> Again, this is if you're intent on using XML configuration.
>

Re: [S2] action mapping with merely default action

Posted by Dave Newton <ne...@yahoo.com>.
(Whoops; wrong button.)

Depending on how your application is laid out you could also put a "catch-all" mapping at the end of your regular mappings, like so:

<action name="*">
  <result>/static/{1}.jsp</result>
</action>

Again, this is if you're intent on using XML configuration.

Dave

--- On Sun, 7/13/08, Pierre Thibaudeau <pi...@gmail.com> wrote:

> From: Pierre Thibaudeau <pi...@gmail.com>
> Subject: [S2] action mapping with merely default action
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Sunday, July 13, 2008, 4:43 PM
> With Struts1, if I wished to render a JSP page without
> bothering with the
> machinery of an action (yet going through the
> filters/interceptors), I would
> have an action mapping as follows:
> 
>         <action path="/home"
> forward="/static/home.jsp" />
> 
> With Struts2, in the same situation, I would do:
> 
>         <action name="home"
> class="com.opensymphony.xwork2.ActionSupport">
>             <result>/static/home.jsp</result>
>         </action>
> 
> This is a case where Struts2 is a lot wordier than Struts1.
>  (I have to do
> this about 15 times, for the site's "static"
> pages...)
> 
> Is there a shorthand version?

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


Re: [S2] action mapping with merely default action

Posted by Dave Newton <ne...@yahoo.com>.
--- On Sun, 7/13/08, Pierre Thibaudeau wrote:
> [S1] <action path="/home" forward="/static/home.jsp" />
> 
> [S2] 
> <action name="home" class="com.opensymphony.xwork2.ActionSupport">
>   <result>/static/home.jsp</result>
> </action>

If you're intent on using XML configuration, leave out the class.

> <action name="home">
>   <result>/static/home.jsp</result>
> </action>

Dave


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