You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Oleg Konovalov <ol...@gmail.com> on 2007/08/11 01:35:13 UTC

Passing value from Struts tag in JSP to Action class

Hi,

 I am populating JSP page with rows retrieved from the database and
represented as a List of Beans in forEach loop:
<c:forEach var="list" items="${OperationsForm.OperationsList}">
          ...
  <c:choose>
            <c:when test="${list.isCompleted =='Y'}" >
                <td width="100">Completed</td>
                <td width="100">&nbsp;</td>
            </c:when>
            <c:otherwise>
                <td width="100">Pending</td>
                    <td width="100"><input type="image" onclick=" *
rowId=value;* form.action='action.do?command=notify'" *value*="${
list.OperationId}" />
                    </td>
            </c:otherwise>
            </c:choose>
            </tr>
        </c:forEach>
Have hidden field:  html:hidden property="*rowId*" value="-1"/>

User is clicking the button corresponding to one of the rows
and I need to pass the  value of that  rowId to the Action class, so it does
something in the database [action completed]
Now how do I pass it , is that the right way of doing it  with calling
request.getSession().getAttribute(rowId) in the Action class ?
As of now I am getting Javascript error "Object doesn't support this
property or method", complaining about *rowId=value;*

Using Struts 1.3

Please help !

TIA,
Oleg.

Re: [OT] Re: Passing value from Struts tag in JSP to Action class

Posted by Oleg Konovalov <ol...@gmail.com>.
That worked for me:
<% String str="form.action='action.do?command=notify&rowId="; %>
onclick="<%= str%><c:out value='${list.rowId}'/>'" />

And in Action:
String rowId = request.getParameter("rowId");


Thank you all,
Oleg.


On 8/13/07, Frank W. Zammetti <fz...@omnytex.com> wrote:
>
> Oleg Konovalov wrote:
> >> make each button on the form a submit button
> > I can't do it, because button has to have image, so I use <input
> > type=image...>
> > Will that work ?
>
> I believe so... best way to be sure would be to try it :) ... but I
> don't see why it wouldn't.
>
> > Also, are you sure this    this.form.rowId.value='${list.rowId}';
> > will work together with my    form.action='action.do?command=notify'
> > I think, Javascript will get screwed up - will complain.
> > And I will have to make all inside a scriplet, something like:
> > onClick="<% form.rowId.value=<*c:out* *value=*'${list.rowId}/>;
> > form.action='action.do?command=notify'  %>"
> > Is that better ?
>
> No, that would be wrong... go ahead and give it a try, you'll get a
> compile error on the JSP because the expression isn't valid.  You may
> however be right to a degree... you may need to use <c:out> in place of
> ${list.rowId} (I think ${list.rowId} is valid JSP 2.0 EL, but that
> assumes JSP 2.0)... I think that's a valid JSP expression... again, give
> it a try, this is a syntactical issue that a minute or two of playing
> will resolve, it's the conceptual part you need to understand first.
>
> Frank
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM/Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Author of "Practical Ajax Projects With Java Technology"
> (2006, Apress, ISBN 1-59059-695-1)
> and "JavaScript, DOM Scripting and Ajax Projects"
> (2007, Apress, ISBN 1-59059-816-4)
> Java Web Parts - http://javawebparts.sourceforge.net
> Supplying the wheel, so you don't have to reinvent it!
>
> >
> >
> > On 8/13/07, Frank W. Zammetti <fz...@omnytex.com> wrote:
> >> Oleg Konovalov wrote:
> >>> No, I am not using any AJAX.
> >>>
> >>> On Submit it supposed to process that row, go to DB and refresh the
> >> whole
> >>> page,
> >>> so to come back on the same page.
> >>>
> >>> Also, my form is declared as <html:form>, so onClick I use
> >>> "form.action='action.do?command=notify'", I can't get rid of it,
> >>> but it doesn't want to coexist with any Javascript.
> >>>
> >>> I would not like to have multiple forms on one JSP page.
> >>>
> >>> So which of your suggestions would you recommend in my case ?
> >>> And how do I get a value of rowId in Action class (notify action),
> >>> via request.getSession().getAttribute("rowId") ?
> >> You wouldn't get it from SESSION, you'd get it from REQUEST... Unless
> >> your intention is to have a session-scoped ActionForm, but then you
> >> wouldn't get at the value as you've shown anyway (in fact, even if it's
> >> a request-scoped from, that's the wrong way to get the value, since
> your
> >> bypassing Struts to do it).
> >>
> >> Since you aren't using AJAX, and you want a single form, all you need
> to
> >> do is set things up in a 100% typical Struts fashion... have the HTML
> >> form submit to the Action you want it to, and connect an ActionForm,
> >> probably request-scoped, to that Action.  Make sure your ActionForm
> >> includes the properly named getter/setter/field for it.  Then, on your
> >> HTML form, add a hidden field with the name rowId, and make each button
> >> on the form a submit button (you can have more than one), and add an
> >> onClick event to it that does this:
> >>
> >> this.form.rowId.value='${list.rowId}';
> >>
> >> That should do it.  Then, in your Action you just do:
> >>
> >> String rowId = form.getRowId();
> >>
> >> ...assuming form is the name of the ActionForm parameter.  That should
> >> be all you need to do.
> >>
> >> Frank
> >>
> >> --
> >> Frank W. Zammetti
> >> Founder and Chief Software Architect
> >> Omnytex Technologies
> >> http://www.omnytex.com
> >> AIM/Yahoo: fzammetti
> >> MSN: fzammetti@hotmail.com
> >> Author of "Practical Ajax Projects With Java Technology"
> >> (2006, Apress, ISBN 1-59059-695-1)
> >> and "JavaScript, DOM Scripting and Ajax Projects"
> >> (2007, Apress, ISBN 1-59059-816-4)
> >> Java Web Parts - http://javawebparts.sourceforge.net
> >> Supplying the wheel, so you don't have to reinvent it!
> >>
> >>> Thank you,
> >>> Oleg.
> >>>
> >>>
> >>>
> >>> On 8/12/07, Frank W. Zammetti <fz...@omnytex.com> wrote:
> >>>> Oleg Konovalov wrote:
> >>>>> I have a bunch of rows [ArrayList of ValueObject Classes], and a
> >> button
> >>>>> corresponding to each row.
> >>>>> I populate the data from each row in forEach loop.
> >>>>> User is supposed to click on one of these buttons [selecting one row
> >> to
> >>>>> process],
> >>>>> and onClick event I need to pass the rowId of the to the new Action
> >>>>> ["notify"] in Action class.
> >>>>> Sounds like a trivial task ?
> >>>>> I am just not sure how to implement that correctly in Struts, pretty
> >> new
> >>>> to
> >>>>> Struts.
> >>>> Depends on what you expect to happen when they click the button... is
> >>>> the entire page refreshed, or are you thinking of doing some AJAX
> here?
> >>>> If the entire page is going to refresh, I'd simply make each row its
> >>>> own form and have the button be a regular submit button.  Add a
> hidden
> >>>> field to each form that has the rowId as its value.  Simple,
> standard,
> >>>> will work just fine.  Alternatively, if you don't like multiple
> forms,
> >>>> then have a single hidden form field which again is the row Id, then
> >>>> onClick of the button do:
> >>>>
> >>>> this.form.rowId.value='${list.rowId}';this.form.submit();
> >>>>
> >>>> If your thinking AJAX here, then there's all sorts of ways you could
> do
> >>>> it.
> >>>>
> >>>>> Maybe I should use
> >>>>> <html:submit src=pic.gif onclick="
> >> form.action='action.do?command=notify'"
> >>>> *
> >>>>> value*="${list.rowId}">
> >>>>> instead of HTML <input type=image...> ?
> >>>> Yes, in theory that could work, but I think it's a bit too
> complicated.
> >>>> Again, if your not thinking AJAX here, just do a plain form
> >>>> submission, it's the best answer.  If you DO want to do AJAX, let us
> >>>> know and we can suggest ways to go about it.
> >>>>
> >>>> Dave's suggestions are good too, it just comes down to how you really
> >>>> want this to work.
> >>>>
> >>>>> TIA,
> >>>>> Oleg.
> >>>> Frank
> >>>>
> >>>> --
> >>>> Frank W. Zammetti
> >>>> Founder and Chief Software Architect
> >>>> Omnytex Technologies
> >>>> http://www.omnytex.com
> >>>> AIM/Yahoo: fzammetti
> >>>> MSN: fzammetti@hotmail.com
> >>>> Author of "Practical Ajax Projects With Java Technology"
> >>>> (2006, Apress, ISBN 1-59059-695-1)
> >>>> and "JavaScript, DOM Scripting and Ajax Projects"
> >>>> (2007, Apress, ISBN 1-59059-816-4)
> >>>> Java Web Parts - http://javawebparts.sourceforge.net
> >>>> Supplying the wheel, so you don't have to reinvent it!
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>
> >>>>
> >>>
> >>>
> ------------------------------------------------------------------------
> >>>
> >>> No virus found in this incoming message.
> >>> Checked by AVG Free Edition.
> >>> Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date:
> >> 8/12/2007 11:03 AM
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
> > ------------------------------------------------------------------------
> >
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date:
> 8/12/2007 11:03 AM
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [OT] Re: Passing value from Struts tag in JSP to Action class

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Oleg Konovalov wrote:
>> make each button on the form a submit button
> I can't do it, because button has to have image, so I use <input
> type=image...>
> Will that work ?

I believe so... best way to be sure would be to try it :) ... but I 
don't see why it wouldn't.

> Also, are you sure this    this.form.rowId.value='${list.rowId}';
> will work together with my    form.action='action.do?command=notify'
> I think, Javascript will get screwed up - will complain.
> And I will have to make all inside a scriplet, something like:
> onClick="<% form.rowId.value=<*c:out* *value=*'${list.rowId}/>;
> form.action='action.do?command=notify'  %>"
> Is that better ?

No, that would be wrong... go ahead and give it a try, you'll get a 
compile error on the JSP because the expression isn't valid.  You may 
however be right to a degree... you may need to use <c:out> in place of 
${list.rowId} (I think ${list.rowId} is valid JSP 2.0 EL, but that 
assumes JSP 2.0)... I think that's a valid JSP expression... again, give 
it a try, this is a syntactical issue that a minute or two of playing 
will resolve, it's the conceptual part you need to understand first.

Frank

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
and "JavaScript, DOM Scripting and Ajax Projects"
  (2007, Apress, ISBN 1-59059-816-4)
Java Web Parts - http://javawebparts.sourceforge.net
  Supplying the wheel, so you don't have to reinvent it!

> 
> 
> On 8/13/07, Frank W. Zammetti <fz...@omnytex.com> wrote:
>> Oleg Konovalov wrote:
>>> No, I am not using any AJAX.
>>>
>>> On Submit it supposed to process that row, go to DB and refresh the
>> whole
>>> page,
>>> so to come back on the same page.
>>>
>>> Also, my form is declared as <html:form>, so onClick I use
>>> "form.action='action.do?command=notify'", I can't get rid of it,
>>> but it doesn't want to coexist with any Javascript.
>>>
>>> I would not like to have multiple forms on one JSP page.
>>>
>>> So which of your suggestions would you recommend in my case ?
>>> And how do I get a value of rowId in Action class (notify action),
>>> via request.getSession().getAttribute("rowId") ?
>> You wouldn't get it from SESSION, you'd get it from REQUEST... Unless
>> your intention is to have a session-scoped ActionForm, but then you
>> wouldn't get at the value as you've shown anyway (in fact, even if it's
>> a request-scoped from, that's the wrong way to get the value, since your
>> bypassing Struts to do it).
>>
>> Since you aren't using AJAX, and you want a single form, all you need to
>> do is set things up in a 100% typical Struts fashion... have the HTML
>> form submit to the Action you want it to, and connect an ActionForm,
>> probably request-scoped, to that Action.  Make sure your ActionForm
>> includes the properly named getter/setter/field for it.  Then, on your
>> HTML form, add a hidden field with the name rowId, and make each button
>> on the form a submit button (you can have more than one), and add an
>> onClick event to it that does this:
>>
>> this.form.rowId.value='${list.rowId}';
>>
>> That should do it.  Then, in your Action you just do:
>>
>> String rowId = form.getRowId();
>>
>> ...assuming form is the name of the ActionForm parameter.  That should
>> be all you need to do.
>>
>> Frank
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>> AIM/Yahoo: fzammetti
>> MSN: fzammetti@hotmail.com
>> Author of "Practical Ajax Projects With Java Technology"
>> (2006, Apress, ISBN 1-59059-695-1)
>> and "JavaScript, DOM Scripting and Ajax Projects"
>> (2007, Apress, ISBN 1-59059-816-4)
>> Java Web Parts - http://javawebparts.sourceforge.net
>> Supplying the wheel, so you don't have to reinvent it!
>>
>>> Thank you,
>>> Oleg.
>>>
>>>
>>>
>>> On 8/12/07, Frank W. Zammetti <fz...@omnytex.com> wrote:
>>>> Oleg Konovalov wrote:
>>>>> I have a bunch of rows [ArrayList of ValueObject Classes], and a
>> button
>>>>> corresponding to each row.
>>>>> I populate the data from each row in forEach loop.
>>>>> User is supposed to click on one of these buttons [selecting one row
>> to
>>>>> process],
>>>>> and onClick event I need to pass the rowId of the to the new Action
>>>>> ["notify"] in Action class.
>>>>> Sounds like a trivial task ?
>>>>> I am just not sure how to implement that correctly in Struts, pretty
>> new
>>>> to
>>>>> Struts.
>>>> Depends on what you expect to happen when they click the button... is
>>>> the entire page refreshed, or are you thinking of doing some AJAX here?
>>>> If the entire page is going to refresh, I'd simply make each row its
>>>> own form and have the button be a regular submit button.  Add a hidden
>>>> field to each form that has the rowId as its value.  Simple, standard,
>>>> will work just fine.  Alternatively, if you don't like multiple forms,
>>>> then have a single hidden form field which again is the row Id, then
>>>> onClick of the button do:
>>>>
>>>> this.form.rowId.value='${list.rowId}';this.form.submit();
>>>>
>>>> If your thinking AJAX here, then there's all sorts of ways you could do
>>>> it.
>>>>
>>>>> Maybe I should use
>>>>> <html:submit src=pic.gif onclick="
>> form.action='action.do?command=notify'"
>>>> *
>>>>> value*="${list.rowId}">
>>>>> instead of HTML <input type=image...> ?
>>>> Yes, in theory that could work, but I think it's a bit too complicated.
>>>> Again, if your not thinking AJAX here, just do a plain form
>>>> submission, it's the best answer.  If you DO want to do AJAX, let us
>>>> know and we can suggest ways to go about it.
>>>>
>>>> Dave's suggestions are good too, it just comes down to how you really
>>>> want this to work.
>>>>
>>>>> TIA,
>>>>> Oleg.
>>>> Frank
>>>>
>>>> --
>>>> Frank W. Zammetti
>>>> Founder and Chief Software Architect
>>>> Omnytex Technologies
>>>> http://www.omnytex.com
>>>> AIM/Yahoo: fzammetti
>>>> MSN: fzammetti@hotmail.com
>>>> Author of "Practical Ajax Projects With Java Technology"
>>>> (2006, Apress, ISBN 1-59059-695-1)
>>>> and "JavaScript, DOM Scripting and Ajax Projects"
>>>> (2007, Apress, ISBN 1-59059-816-4)
>>>> Java Web Parts - http://javawebparts.sourceforge.net
>>>> Supplying the wheel, so you don't have to reinvent it!
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> No virus found in this incoming message.
>>> Checked by AVG Free Edition.
>>> Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date:
>> 8/12/2007 11:03 AM
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> ------------------------------------------------------------------------
> 
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date: 8/12/2007 11:03 AM

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


Re: [OT] Re: Passing value from Struts tag in JSP to Action class

Posted by Oleg Konovalov <ol...@gmail.com>.
>make each button on the form a submit button
I can't do it, because button has to have image, so I use <input
type=image...>
Will that work ?

Also, are you sure this    this.form.rowId.value='${list.rowId}';
will work together with my    form.action='action.do?command=notify'
I think, Javascript will get screwed up - will complain.
And I will have to make all inside a scriplet, something like:
onClick="<% form.rowId.value=<*c:out* *value=*'${list.rowId}/>;
form.action='action.do?command=notify'  %>"
Is that better ?



On 8/13/07, Frank W. Zammetti <fz...@omnytex.com> wrote:
>
> Oleg Konovalov wrote:
> > No, I am not using any AJAX.
> >
> > On Submit it supposed to process that row, go to DB and refresh the
> whole
> > page,
> > so to come back on the same page.
> >
> > Also, my form is declared as <html:form>, so onClick I use
> > "form.action='action.do?command=notify'", I can't get rid of it,
> > but it doesn't want to coexist with any Javascript.
> >
> > I would not like to have multiple forms on one JSP page.
> >
> > So which of your suggestions would you recommend in my case ?
> > And how do I get a value of rowId in Action class (notify action),
> > via request.getSession().getAttribute("rowId") ?
>
> You wouldn't get it from SESSION, you'd get it from REQUEST... Unless
> your intention is to have a session-scoped ActionForm, but then you
> wouldn't get at the value as you've shown anyway (in fact, even if it's
> a request-scoped from, that's the wrong way to get the value, since your
> bypassing Struts to do it).
>
> Since you aren't using AJAX, and you want a single form, all you need to
> do is set things up in a 100% typical Struts fashion... have the HTML
> form submit to the Action you want it to, and connect an ActionForm,
> probably request-scoped, to that Action.  Make sure your ActionForm
> includes the properly named getter/setter/field for it.  Then, on your
> HTML form, add a hidden field with the name rowId, and make each button
> on the form a submit button (you can have more than one), and add an
> onClick event to it that does this:
>
> this.form.rowId.value='${list.rowId}';
>
> That should do it.  Then, in your Action you just do:
>
> String rowId = form.getRowId();
>
> ...assuming form is the name of the ActionForm parameter.  That should
> be all you need to do.
>
> Frank
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM/Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Author of "Practical Ajax Projects With Java Technology"
> (2006, Apress, ISBN 1-59059-695-1)
> and "JavaScript, DOM Scripting and Ajax Projects"
> (2007, Apress, ISBN 1-59059-816-4)
> Java Web Parts - http://javawebparts.sourceforge.net
> Supplying the wheel, so you don't have to reinvent it!
>
> > Thank you,
> > Oleg.
> >
> >
> >
> > On 8/12/07, Frank W. Zammetti <fz...@omnytex.com> wrote:
> >> Oleg Konovalov wrote:
> >>> I have a bunch of rows [ArrayList of ValueObject Classes], and a
> button
> >>> corresponding to each row.
> >>> I populate the data from each row in forEach loop.
> >>> User is supposed to click on one of these buttons [selecting one row
> to
> >>> process],
> >>> and onClick event I need to pass the rowId of the to the new Action
> >>> ["notify"] in Action class.
> >>> Sounds like a trivial task ?
> >>> I am just not sure how to implement that correctly in Struts, pretty
> new
> >> to
> >>> Struts.
> >> Depends on what you expect to happen when they click the button... is
> >> the entire page refreshed, or are you thinking of doing some AJAX here?
> >> If the entire page is going to refresh, I'd simply make each row its
> >> own form and have the button be a regular submit button.  Add a hidden
> >> field to each form that has the rowId as its value.  Simple, standard,
> >> will work just fine.  Alternatively, if you don't like multiple forms,
> >> then have a single hidden form field which again is the row Id, then
> >> onClick of the button do:
> >>
> >> this.form.rowId.value='${list.rowId}';this.form.submit();
> >>
> >> If your thinking AJAX here, then there's all sorts of ways you could do
> >> it.
> >>
> >>> Maybe I should use
> >>> <html:submit src=pic.gif onclick="
> form.action='action.do?command=notify'"
> >> *
> >>> value*="${list.rowId}">
> >>> instead of HTML <input type=image...> ?
> >> Yes, in theory that could work, but I think it's a bit too complicated.
> >> Again, if your not thinking AJAX here, just do a plain form
> >> submission, it's the best answer.  If you DO want to do AJAX, let us
> >> know and we can suggest ways to go about it.
> >>
> >> Dave's suggestions are good too, it just comes down to how you really
> >> want this to work.
> >>
> >>> TIA,
> >>> Oleg.
> >> Frank
> >>
> >> --
> >> Frank W. Zammetti
> >> Founder and Chief Software Architect
> >> Omnytex Technologies
> >> http://www.omnytex.com
> >> AIM/Yahoo: fzammetti
> >> MSN: fzammetti@hotmail.com
> >> Author of "Practical Ajax Projects With Java Technology"
> >> (2006, Apress, ISBN 1-59059-695-1)
> >> and "JavaScript, DOM Scripting and Ajax Projects"
> >> (2007, Apress, ISBN 1-59059-816-4)
> >> Java Web Parts - http://javawebparts.sourceforge.net
> >> Supplying the wheel, so you don't have to reinvent it!
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
> > ------------------------------------------------------------------------
> >
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date:
> 8/12/2007 11:03 AM
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [OT] Re: Passing value from Struts tag in JSP to Action class

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Oleg Konovalov wrote:
> No, I am not using any AJAX.
> 
> On Submit it supposed to process that row, go to DB and refresh the whole
> page,
> so to come back on the same page.
> 
> Also, my form is declared as <html:form>, so onClick I use
> "form.action='action.do?command=notify'", I can't get rid of it,
> but it doesn't want to coexist with any Javascript.
> 
> I would not like to have multiple forms on one JSP page.
> 
> So which of your suggestions would you recommend in my case ?
> And how do I get a value of rowId in Action class (notify action),
> via request.getSession().getAttribute("rowId") ?

You wouldn't get it from SESSION, you'd get it from REQUEST... Unless 
your intention is to have a session-scoped ActionForm, but then you 
wouldn't get at the value as you've shown anyway (in fact, even if it's 
a request-scoped from, that's the wrong way to get the value, since your 
bypassing Struts to do it).

Since you aren't using AJAX, and you want a single form, all you need to 
do is set things up in a 100% typical Struts fashion... have the HTML 
form submit to the Action you want it to, and connect an ActionForm, 
probably request-scoped, to that Action.  Make sure your ActionForm 
includes the properly named getter/setter/field for it.  Then, on your 
HTML form, add a hidden field with the name rowId, and make each button 
on the form a submit button (you can have more than one), and add an 
onClick event to it that does this:

this.form.rowId.value='${list.rowId}';

That should do it.  Then, in your Action you just do:

String rowId = form.getRowId();

...assuming form is the name of the ActionForm parameter.  That should 
be all you need to do.

Frank

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
and "JavaScript, DOM Scripting and Ajax Projects"
  (2007, Apress, ISBN 1-59059-816-4)
Java Web Parts - http://javawebparts.sourceforge.net
  Supplying the wheel, so you don't have to reinvent it!

> Thank you,
> Oleg.
> 
> 
> 
> On 8/12/07, Frank W. Zammetti <fz...@omnytex.com> wrote:
>> Oleg Konovalov wrote:
>>> I have a bunch of rows [ArrayList of ValueObject Classes], and a button
>>> corresponding to each row.
>>> I populate the data from each row in forEach loop.
>>> User is supposed to click on one of these buttons [selecting one row to
>>> process],
>>> and onClick event I need to pass the rowId of the to the new Action
>>> ["notify"] in Action class.
>>> Sounds like a trivial task ?
>>> I am just not sure how to implement that correctly in Struts, pretty new
>> to
>>> Struts.
>> Depends on what you expect to happen when they click the button... is
>> the entire page refreshed, or are you thinking of doing some AJAX here?
>> If the entire page is going to refresh, I'd simply make each row its
>> own form and have the button be a regular submit button.  Add a hidden
>> field to each form that has the rowId as its value.  Simple, standard,
>> will work just fine.  Alternatively, if you don't like multiple forms,
>> then have a single hidden form field which again is the row Id, then
>> onClick of the button do:
>>
>> this.form.rowId.value='${list.rowId}';this.form.submit();
>>
>> If your thinking AJAX here, then there's all sorts of ways you could do
>> it.
>>
>>> Maybe I should use
>>> <html:submit src=pic.gif onclick="form.action='action.do?command=notify'"
>> *
>>> value*="${list.rowId}">
>>> instead of HTML <input type=image...> ?
>> Yes, in theory that could work, but I think it's a bit too complicated.
>> Again, if your not thinking AJAX here, just do a plain form
>> submission, it's the best answer.  If you DO want to do AJAX, let us
>> know and we can suggest ways to go about it.
>>
>> Dave's suggestions are good too, it just comes down to how you really
>> want this to work.
>>
>>> TIA,
>>> Oleg.
>> Frank
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>> AIM/Yahoo: fzammetti
>> MSN: fzammetti@hotmail.com
>> Author of "Practical Ajax Projects With Java Technology"
>> (2006, Apress, ISBN 1-59059-695-1)
>> and "JavaScript, DOM Scripting and Ajax Projects"
>> (2007, Apress, ISBN 1-59059-816-4)
>> Java Web Parts - http://javawebparts.sourceforge.net
>> Supplying the wheel, so you don't have to reinvent it!
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> ------------------------------------------------------------------------
> 
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date: 8/12/2007 11:03 AM



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


Re: [OT] Re: Passing value from Struts tag in JSP to Action class

Posted by Oleg Konovalov <ol...@gmail.com>.
No, I am not using any AJAX.

On Submit it supposed to process that row, go to DB and refresh the whole
page,
so to come back on the same page.

Also, my form is declared as <html:form>, so onClick I use
"form.action='action.do?command=notify'", I can't get rid of it,
but it doesn't want to coexist with any Javascript.

I would not like to have multiple forms on one JSP page.

So which of your suggestions would you recommend in my case ?
And how do I get a value of rowId in Action class (notify action),
via request.getSession().getAttribute("rowId") ?

Thank you,
Oleg.



On 8/12/07, Frank W. Zammetti <fz...@omnytex.com> wrote:
>
> Oleg Konovalov wrote:
> > I have a bunch of rows [ArrayList of ValueObject Classes], and a button
> > corresponding to each row.
> > I populate the data from each row in forEach loop.
> > User is supposed to click on one of these buttons [selecting one row to
> > process],
> > and onClick event I need to pass the rowId of the to the new Action
> > ["notify"] in Action class.
> > Sounds like a trivial task ?
> > I am just not sure how to implement that correctly in Struts, pretty new
> to
> > Struts.
>
> Depends on what you expect to happen when they click the button... is
> the entire page refreshed, or are you thinking of doing some AJAX here?
> If the entire page is going to refresh, I'd simply make each row its
> own form and have the button be a regular submit button.  Add a hidden
> field to each form that has the rowId as its value.  Simple, standard,
> will work just fine.  Alternatively, if you don't like multiple forms,
> then have a single hidden form field which again is the row Id, then
> onClick of the button do:
>
> this.form.rowId.value='${list.rowId}';this.form.submit();
>
> If your thinking AJAX here, then there's all sorts of ways you could do
> it.
>
> > Maybe I should use
> > <html:submit src=pic.gif onclick="form.action='action.do?command=notify'"
> *
> > value*="${list.rowId}">
> > instead of HTML <input type=image...> ?
>
> Yes, in theory that could work, but I think it's a bit too complicated.
> Again, if your not thinking AJAX here, just do a plain form
> submission, it's the best answer.  If you DO want to do AJAX, let us
> know and we can suggest ways to go about it.
>
> Dave's suggestions are good too, it just comes down to how you really
> want this to work.
>
> > TIA,
> > Oleg.
>
> Frank
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM/Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Author of "Practical Ajax Projects With Java Technology"
> (2006, Apress, ISBN 1-59059-695-1)
> and "JavaScript, DOM Scripting and Ajax Projects"
> (2007, Apress, ISBN 1-59059-816-4)
> Java Web Parts - http://javawebparts.sourceforge.net
> Supplying the wheel, so you don't have to reinvent it!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [OT] Re: Passing value from Struts tag in JSP to Action class

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Oleg Konovalov wrote:
> I have a bunch of rows [ArrayList of ValueObject Classes], and a button
> corresponding to each row.
> I populate the data from each row in forEach loop.
> User is supposed to click on one of these buttons [selecting one row to
> process],
> and onClick event I need to pass the rowId of the to the new Action
> ["notify"] in Action class.
> Sounds like a trivial task ?
> I am just not sure how to implement that correctly in Struts, pretty new to
> Struts.

Depends on what you expect to happen when they click the button... is 
the entire page refreshed, or are you thinking of doing some AJAX here? 
  If the entire page is going to refresh, I'd simply make each row its 
own form and have the button be a regular submit button.  Add a hidden 
field to each form that has the rowId as its value.  Simple, standard, 
will work just fine.  Alternatively, if you don't like multiple forms, 
then have a single hidden form field which again is the row Id, then 
onClick of the button do:

this.form.rowId.value='${list.rowId}';this.form.submit();

If your thinking AJAX here, then there's all sorts of ways you could do it.

> Maybe I should use
> <html:submit src=pic.gif onclick="form.action='action.do?command=notify'" *
> value*="${list.rowId}">
> instead of HTML <input type=image...> ?

Yes, in theory that could work, but I think it's a bit too complicated. 
  Again, if your not thinking AJAX here, just do a plain form 
submission, it's the best answer.  If you DO want to do AJAX, let us 
know and we can suggest ways to go about it.

Dave's suggestions are good too, it just comes down to how you really 
want this to work.

> TIA,
> Oleg.

Frank

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
and "JavaScript, DOM Scripting and Ajax Projects"
  (2007, Apress, ISBN 1-59059-816-4)
Java Web Parts - http://javawebparts.sourceforge.net
  Supplying the wheel, so you don't have to reinvent it!

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


Re: [OT] Re: Passing value from Struts tag in JSP to Action class

Posted by Dave Newton <ne...@yahoo.com>.
--- Oleg Konovalov <ol...@gmail.com> wrote:
> As I mentioned in the original e-mail:
> 
> Have hidden field:
> <html:hidden property="*rowId*" value="-1"/>

Yeah, but... that's a form value, not a JavaScript
variable. The "onclick" attribute expects valid
JavaScript.

> I have a bunch of rows and a button corresponding to

> each row.

If you just want a link with a row ID then just build
a URL with a rowId parameter; you can use an image as
a link if you want.

If you're dead-set on using an actual form then you
could either build a small form with the rowId as a
hidden element for each row or set the value of the
hidden rowId element.

You can't do that just by saying "rowId=blahBlah" you
have to access the DOM rowId form field object (using
Prototype or similar, something like:

$('rowId').value=blahBlah;

If you're not doing anything destructive I'd probably
just make a text or image link w/ the parameter in the
URL. If it's destructive then I'd put it behind a
form. That's just me, though; other people will chime
in with other ideas and methods.

d.



      ____________________________________________________________________________________
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 


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


Re: [OT] Re: Passing value from Struts tag in JSP to Action class

Posted by Oleg Konovalov <ol...@gmail.com>.
As I mentioned in the original e-mail:

Have hidden field:
<html:hidden property="*rowId*" value="-1"/>

I have a bunch of rows [ArrayList of ValueObject Classes], and a button
corresponding to each row.
I populate the data from each row in forEach loop.
User is supposed to click on one of these buttons [selecting one row to
process],
and onClick event I need to pass the rowId of the to the new Action
["notify"] in Action class.
Sounds like a trivial task ?
I am just not sure how to implement that correctly in Struts, pretty new to
Struts.

Maybe I should use
<html:submit src=pic.gif onclick="form.action='action.do?command=notify'" *
value*="${list.rowId}">
instead of HTML <input type=image...> ?

Then how do I catch that rowId [now Submit Value] in Action class ?

TIA,
Oleg.



On 8/11/07, Frank W. Zammetti <fz...@omnytex.com> wrote:
>
> What is rowId?  That's not a standard attribute of the <input> tag,
> hence the error makes sense I think, assuming it's being interpreted
> equivalent to this.rowId... also, value doesn't have any context here, I
> assume you mean to do this.value (which it may be interpreted as
> anyway), but maybe not... what are you actually trying to do?
>
> Frank
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM/Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Author of "Practical Ajax Projects With Java Technology"
>   (2006, Apress, ISBN 1-59059-695-1)
> and "JavaScript, DOM Scripting and Ajax Projects"
>   (2007, Apress, ISBN 1-59059-816-4)
> Java Web Parts - http://javawebparts.sourceforge.net
>   Supplying the wheel, so you don't have to reinvent it!
>
> Oleg Konovalov wrote:
> > Dave,
> >
> > What am I doing wrong in that Javascript ?
> > Honestly, I don't see it.
> > Please help !
> >
> > Thank you,
> > Oleg.
> >
> >
> >
> > On 8/10/07, Dave Newton <ne...@yahoo.com> wrote:
> >> --- Oleg Konovalov <ol...@gmail.com> wrote:
> >>>        <input type="image" onclick="rowId=value;"
> >>> As of now I am getting Javascript error "Object
> >>> doesn't support this property or method",
> >> complaining
> >>> about *rowId=value;*
> >> The "onclick" attribute must have valid JavaScript.
> >>
> >> d.
> >>
> >>
> >>
> >>
> >>
> >>
> ____________________________________________________________________________________
> >> Take the Internet to Go: Yahoo!Go puts the Internet in your pocket:
> mail,
> >> news, photos & more.
> >> http://mobile.yahoo.com/go?refer=1GNXIC
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
> > ------------------------------------------------------------------------
> >
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.5.476 / Virus Database: 269.11.13/946 - Release Date:
> 8/10/2007 3:50 PM
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [OT] Re: Passing value from Struts tag in JSP to Action class

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
What is rowId?  That's not a standard attribute of the <input> tag, 
hence the error makes sense I think, assuming it's being interpreted 
equivalent to this.rowId... also, value doesn't have any context here, I 
assume you mean to do this.value (which it may be interpreted as 
anyway), but maybe not... what are you actually trying to do?

Frank

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
and "JavaScript, DOM Scripting and Ajax Projects"
  (2007, Apress, ISBN 1-59059-816-4)
Java Web Parts - http://javawebparts.sourceforge.net
  Supplying the wheel, so you don't have to reinvent it!

Oleg Konovalov wrote:
> Dave,
> 
> What am I doing wrong in that Javascript ?
> Honestly, I don't see it.
> Please help !
> 
> Thank you,
> Oleg.
> 
> 
> 
> On 8/10/07, Dave Newton <ne...@yahoo.com> wrote:
>> --- Oleg Konovalov <ol...@gmail.com> wrote:
>>>        <input type="image" onclick="rowId=value;"
>>> As of now I am getting Javascript error "Object
>>> doesn't support this property or method",
>> complaining
>>> about *rowId=value;*
>> The "onclick" attribute must have valid JavaScript.
>>
>> d.
>>
>>
>>
>>
>>
>> ____________________________________________________________________________________
>> Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail,
>> news, photos & more.
>> http://mobile.yahoo.com/go?refer=1GNXIC
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> ------------------------------------------------------------------------
> 
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.476 / Virus Database: 269.11.13/946 - Release Date: 8/10/2007 3:50 PM

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


Re: [OT] Re: Passing value from Struts tag in JSP to Action class

Posted by Oleg Konovalov <ol...@gmail.com>.
Dave,

What am I doing wrong in that Javascript ?
Honestly, I don't see it.
Please help !

Thank you,
Oleg.



On 8/10/07, Dave Newton <ne...@yahoo.com> wrote:
>
> --- Oleg Konovalov <ol...@gmail.com> wrote:
> >        <input type="image" onclick="rowId=value;"
> > As of now I am getting Javascript error "Object
> > doesn't support this property or method",
> complaining
> > about *rowId=value;*
>
> The "onclick" attribute must have valid JavaScript.
>
> d.
>
>
>
>
>
> ____________________________________________________________________________________
> Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail,
> news, photos & more.
> http://mobile.yahoo.com/go?refer=1GNXIC
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

[OT] Re: Passing value from Struts tag in JSP to Action class

Posted by Dave Newton <ne...@yahoo.com>.
--- Oleg Konovalov <ol...@gmail.com> wrote:
>        <input type="image" onclick="rowId=value;" 
> As of now I am getting Javascript error "Object
> doesn't support this property or method",
complaining 
> about *rowId=value;*

The "onclick" attribute must have valid JavaScript.

d.



       
____________________________________________________________________________________
Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. 
http://mobile.yahoo.com/go?refer=1GNXIC

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