Hi Dave, 

Thanks for your reply. Sorry, I was away a few days for the midsummer holidays 
(here in Sweden). 

I couldn't find any instructions regarding being allowed to attach files to 
such mails. So I didn't take the risk. Also copying the content of the files 
here was probably not proper either, was it? Please tell me if it is possible 
to attach files and I'll send you the files. Here is some more explanations 
about the issue: 

In my HellowWorldAction.java I used a private static variable helloCount with 
belonging get/set methods. As you see in the examples it returned empty in the 
jsp when invoked inside <p> tags and correct value when  outside the tags, 
while the static variable for DAY-OF-WEEK could return its value when invoked 
inside <p> tags. 

Just in order to test the situation about static variables in actions, I 
defined an instance variable instanceCount set to the value of helloCount in 
the execute method, and with its own get/set methods. This returned its value 
even inside <p> tags as expected. 

So, my question was: Why a difference between two static variables in Java? 
also the reason to the difference between static and instance variables in the 
same action class?

Best regards
/// Sam



--- On Wed, 6/20/12, Dave Newton <davelnew...@gmail.com> wrote:

> From: Dave Newton <davelnew...@gmail.com>
> Subject: Re: fetching a static variable's value from within a JSP page
> To: "Struts Users Mailing List" <user@struts.apache.org>
> Date: Wednesday, June 20, 2012, 12:43 PM
> First, paragraph tags have *zero* to
> do with it, regardless of any behavior
> you're seeing.
> 
> On Wed, Jun 20, 2012 at 12:24 PM, Sam Cyrus wrote:
> 
> >    <p>It is possible to fetch the
> static helloCount outside paragraph
> > tags: </p> <s:property value="helloCount"
> />
> >
> 
> I'm a little surprised that works without a getter in the
> action.
> 
>    <p>Inside paragraph tags the static
> helloCount preceded by @-prefix
> > returns  <s:property value="@helloCount"
> />  empty times!</p>
> >
> 
> This isn't the syntax for static property access.
> 
> 
> >    <p>Inside paragraph tags the static
> helloCount without @-prefix returns
> >  <s:property value="instanceCount" /> 
> empty times!</p>
> >
> 
> Why is a static property called something with an "instance"
> name? Are you
> sure you're looking at what you think you are?
> 
>    <p>By assigning the static value to
> an instance variable inside the
> > execute method <s:property value="instanceCount"
> /> works well inside
> > p-tags</p>
> >
> 
> Sure; this would call `getInstanceCount()` (or in some
> versions of S2, it
> can just be a public property).
> 
> 
> >    <p> Still strange! The DAY-OF-WEEK
> is static but possible to fetch
> > inside p-tags: <s:property
> value="@java.util.Calendar@DAY_OF_WEEK"/> as
> > expected</p>
> >
> 
> Nothing strange, that's how static property access works.
> 
> Without knowing what the action looks like, it's impossible
> to address
> things beyond the above, because we don't know anything
> about what's on the
> value stack.
> 
> Dave
>

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

Reply via email to