You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Muhammad Momin Rashid <mo...@amaana.com> on 2004/08/25 08:44:51 UTC
updating values in a collection of beans through JSP
Hello,
I have a collection of a perticular type of bean. I am displaying the
values of fields in each bean (bean values are of type strings, boolean
etc.) inside a logic:iterate. The problem is when I change any value in the
webpage, the bean in the collection does not get updated. Can anyone guide
me how to accomplish this?
Thanks for your time and effort
Regards,
Muhammad Momin Rashid.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: updating values in a collection of beans through JSP
Posted by Muhammad Momin Rashid <mo...@amaana.com>.
Hello again,
Thank you for your quick response, well perhaps it should update the
collection (actually the values of the beans contained within the
collection), but i doubt that it would be really as simple as that.
As per my observation the collection is not being updated, I've already
confirmed this in my action class.
Regards,
Muhammad Momin Rashid.
"Richard Yee" <ry...@cruzio.com> wrote in message
news:6.1.2.0.2.20040824235203.0036e1f0@mail.cruzio.com...
> Muhammad,
> The JSP is evaluated on the server and then sent to the browser. When you
> change a value on the web page, you submit the form to an Action class
> which then takes the form properties and should update your collection and
> then persist it or put it in request or session scope. You can then
> forward to another JSP to re-display the updated collection.
>
> -Richard
>
> At 11:44 PM 8/24/2004, you wrote:
>>Hello,
>>
>>I have a collection of a perticular type of bean. I am displaying the
>>values of fields in each bean (bean values are of type strings, boolean
>>etc.) inside a logic:iterate. The problem is when I change any value in
>>the
>>webpage, the bean in the collection does not get updated. Can anyone
>>guide
>>me how to accomplish this?
>>
>>Thanks for your time and effort
>>
>>Regards,
>>Muhammad Momin Rashid.
>>
>>
>>
>>
>>---------------------------------------------------------------------
>>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: updating values in a collection of beans through JSP
Posted by Richard Yee <ry...@cruzio.com>.
Sebastian,
I'm not sure what the "it" your are referring to is when you wrote,
"I always thought if I pass a actionform to the JSP and it sets the
actionform after user clicks
submit, the values will be updated in the scope."
The JSP is run on the server and generates the html that is sent to the
browser. When you click the submit button, an HTML form is sent to your
Action class specified in the action mapping that corresponds to the action
attribute of the form. It is in this action and the form bean that is
configured for the action that the form values are processed.
Some code that might help debugging your jsps and actions is the
inspectmessages.jsp from this
article:http://javaboutique.internet.com/tutorials/excep_struts/
I sometimes put this code at the bottom of all my jsps as I am developing
b/c it shows what values are available to the JSP. Once I finish developing
the page, I delete it.
<%@ page import="java.util.*" %>
<%@ page import="org.apache.struts.*" %>
<%@ page import="org.apache.struts.util.*" %>
<%@ page import="org.apache.struts.action.*" %>
<%
// Print all attributes in the request object
out.println("<p><b>All Attributes in request scope:</b>");
Enumeration paramNames = request.getAttributeNames();
while (paramNames.hasMoreElements()) {
String name = (String) paramNames.nextElement();
Object values = request.getAttribute(name);
out.println("<br> " + name + ":" + values);
}
// Print all attributes in the session object
out.println("<p><b>All Attributes in session scope:</b>");
paramNames = session.getAttributeNames();
while (paramNames.hasMoreElements()) {
String name = (String) paramNames.nextElement();
Object values = session.getAttribute(name);
out.println("<br> " + name + ":" + values);
}
out.println("<p><b>Data in ActionMessages:</b>");
// Get the ActionMessages
Object o = request.getAttribute(Globals.MESSAGE_KEY);
if (o != null) {
ActionMessages ae = (ActionMessages)o;
// Get the locale and message resources bundle
Locale locale =
(Locale)session.getAttribute(Globals.LOCALE_KEY);
MessageResources messages =
(MessageResources)request.getAttribute
(Globals.MESSAGES_KEY);
// Loop thru all the labels in the ActionMessage's
for (Iterator i = ae.properties(); i.hasNext();) {
String property = (String)i.next();
out.println("<br>property " + property + ": ");
// Get all messages for this label
for (Iterator it = ae.get(property); it.hasNext();) {
ActionMessage a = (ActionMessage)it.next();
String key = a.getKey();
Object[] values = a.getValues();
out.println(" [key=" + key +
", message=" +
messages.getMessage(locale,key,values) +
"]");
}
}
}
%>
-Richard
At 01:25 AM 8/25/2004, you wrote:
>Hi Richard
>
> >From what you describe below, we need to put it into the scope again
>after action class receives the actionform? I always thought if I pass a
>actionform to the JSP and it sets the actionform after user clicks
>submit, the values will be updated in the scope. Weird, my application
>should break in that case..I must be doing something wrong but somehow
>it still works..
>
>Sebastian Ho
>
>
>On Wed, 2004-08-25 at 14:54, Richard Yee wrote:
> > Muhammad,
> > The JSP is evaluated on the server and then sent to the browser. When you
> > change a value on the web page, you submit the form to an Action class
> > which then takes the form properties and should update your collection and
> > then persist it or put it in request or session scope. You can then
> forward
> > to another JSP to re-display the updated collection.
> >
> > -Richard
> >
> > At 11:44 PM 8/24/2004, you wrote:
> > >Hello,
> > >
> > >I have a collection of a perticular type of bean. I am displaying the
> > >values of fields in each bean (bean values are of type strings, boolean
> > >etc.) inside a logic:iterate. The problem is when I change any value
> in the
> > >webpage, the bean in the collection does not get updated. Can anyone
> guide
> > >me how to accomplish this?
> > >
> > >Thanks for your time and effort
> > >
> > >Regards,
> > >Muhammad Momin Rashid.
> > >
> > >
> > >
> > >
> > >---------------------------------------------------------------------
> > >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
> >
> >
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
Re: updating values in a collection of beans through JSP
Posted by Sebastian Ho <se...@bii.a-star.edu.sg>.
Hi Richard
>>From what you describe below, we need to put it into the scope again
after action class receives the actionform? I always thought if I pass a
actionform to the JSP and it sets the actionform after user clicks
submit, the values will be updated in the scope. Weird, my application
should break in that case..I must be doing something wrong but somehow
it still works..
Sebastian Ho
On Wed, 2004-08-25 at 14:54, Richard Yee wrote:
> Muhammad,
> The JSP is evaluated on the server and then sent to the browser. When you
> change a value on the web page, you submit the form to an Action class
> which then takes the form properties and should update your collection and
> then persist it or put it in request or session scope. You can then forward
> to another JSP to re-display the updated collection.
>
> -Richard
>
> At 11:44 PM 8/24/2004, you wrote:
> >Hello,
> >
> >I have a collection of a perticular type of bean. I am displaying the
> >values of fields in each bean (bean values are of type strings, boolean
> >etc.) inside a logic:iterate. The problem is when I change any value in the
> >webpage, the bean in the collection does not get updated. Can anyone guide
> >me how to accomplish this?
> >
> >Thanks for your time and effort
> >
> >Regards,
> >Muhammad Momin Rashid.
> >
> >
> >
> >
> >---------------------------------------------------------------------
> >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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: updating values in a collection of beans through JSP
Posted by Richard Yee <ry...@cruzio.com>.
Muhammad,
The JSP is evaluated on the server and then sent to the browser. When you
change a value on the web page, you submit the form to an Action class
which then takes the form properties and should update your collection and
then persist it or put it in request or session scope. You can then forward
to another JSP to re-display the updated collection.
-Richard
At 11:44 PM 8/24/2004, you wrote:
>Hello,
>
>I have a collection of a perticular type of bean. I am displaying the
>values of fields in each bean (bean values are of type strings, boolean
>etc.) inside a logic:iterate. The problem is when I change any value in the
>webpage, the bean in the collection does not get updated. Can anyone guide
>me how to accomplish this?
>
>Thanks for your time and effort
>
>Regards,
>Muhammad Momin Rashid.
>
>
>
>
>---------------------------------------------------------------------
>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: updating values in a collection of beans through JSP
Posted by Rick Reumann <st...@reumann.net>.
Olve Sæther Hansen wrote:
> I am also struggeling with the same problem.. As you said earlier, a
> demo would be helpful.
I have a demo app and some notes here explaining how to accomplish this:
http://www.reumann.net/struts/nested.do
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: updating values in a collection of beans through JSP
Posted by Olve Sæther Hansen <ol...@uib.no>.
Muhammad Momin Rashid wrote:
>Finally I figured out the solution on my own, I would like to thank
>everyone who made an effort to help me resolve the issue at hand.
>
>Regards,
>Muhammad Momin Rashid.
>
>"Muhammad Momin Rashid" <mo...@amaana.com> wrote in message
>news:cghch0$qal$1@sea.gmane.org...
>
>
>>Hello,
>>
>>I have a collection of a perticular type of bean. I am displaying the
>>values of fields in each bean (bean values are of type strings, boolean
>>etc.) inside a logic:iterate. The problem is when I change any value in
>>the webpage, the bean in the collection does not get updated. Can anyone
>>guide me how to accomplish this?
>>
>>Thanks for your time and effort
>>
>>Regards,
>>Muhammad Momin Rashid.
>>
>>
>
>
>
>
I am also struggeling with the same problem.. As you said earlier, a
demo would be helpful.
Could you post your solution please?
Regards
Olve S. Hansen
Re: updating values in a collection of beans through JSP
Posted by Muhammad Momin Rashid <mo...@amaana.com>.
Finally I figured out the solution on my own, I would like to thank
everyone who made an effort to help me resolve the issue at hand.
Regards,
Muhammad Momin Rashid.
"Muhammad Momin Rashid" <mo...@amaana.com> wrote in message
news:cghch0$qal$1@sea.gmane.org...
> Hello,
>
> I have a collection of a perticular type of bean. I am displaying the
> values of fields in each bean (bean values are of type strings, boolean
> etc.) inside a logic:iterate. The problem is when I change any value in
> the webpage, the bean in the collection does not get updated. Can anyone
> guide me how to accomplish this?
>
> Thanks for your time and effort
>
> Regards,
> Muhammad Momin Rashid.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org