You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Petr Blahos <Pe...@seznam.cz> on 2007/02/22 14:47:53 UTC

[s2] Passing parameters to an action

Hi all,
I was wondering how I could possibly solve this: I have an action in which
I construct quite a complex data structure. From that data structure I display
some tables and create some charts. Now, I have got this one big-ass java
class - extending ActionSupport, in which I do all the stuff - create data and
have functions for painting charts in temporary files. In JSP I do the obvious:
      <s:iterator ...>
      ...... paint table
      </s:iterator>
then the graphs:
	<s:iterator value="%{getCharts(top)}">
		<img src="<%=request.getContextPath()%>/servlet/DisplayChart?filename=<s:property />" border=0">
	</s:iterator>
where getCharts(top) is a function that constructs the charts and saves it in files
and returns a list of filenames, and servlet/DisplayChart simply converts the 
filename to full path and filename.

Now, the thing is, I would like to separate the code for painting the charts in a different
file, and do something like this:
       <s:iterator value="%{getChartsData(top)}">
                <s:action namespace="charts" name="ErrorStat" executeResult="true"/>
               <%--          ^^^^^^^^^^^^^^^^^^^^^^^^^^^    --%>
       </s:iterator>
But I need to pass current "top" to the action (or set a property in this action) but I
have no idea how. I gather that I should be able to get to the "top" in my java class
but it seems to be quite far fetched. I would rather set a property in this action.
I have tried playing with <s:property, <s:push, <s:param without any success.

Am I missing something or is my idea totally wrong?

Thanks a million,
Petr Blahoš

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


Re: [s2] Passing parameters to an action

Posted by Petr Blahos <Pe...@seznam.cz>.
>  Hi all,
>  I was wondering how I could possibly solve this: I have an action in which
>  I construct quite a complex data structure. From that data structure I display
>  some tables and create some charts. Now, I have got this one big-ass java
>  class - extending ActionSupport, in which I do all the stuff - create data and
>  have functions for painting charts in temporary files. 
[...]
>  Now, the thing is, I would like to separate the code for painting the charts in
>  a different
>  file, and do something like this:
>         <s:iterator value="%{getChartsData(top)}">
>                  <s:action namespace="charts" name="ErrorStat"
>  executeResult="true"/>
>                 <%--          ^^^^^^^^^^^^^^^^^^^^^^^^^^^    --%>
>         </s:iterator>
>  But I need to pass current "top" to the action (or set a property in this
>  action) but I
>  have no idea how. I gather that I should be able to get to the "top" in my java
>  class

So I've finally found out how it can be done. Through action context I can get
value stack and find any possible value being already there. 

ActionContext.getContext().getValueStack().findValue("valuename");

Not exactly nice as the parameter is not pushed to the action by the caller
but the action must dig on the value stack for it, but at least it works...

Petr


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