You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brett <br...@thebault.co.uk> on 2005/07/12 13:23:33 UTC
Loosing my form bean instance...
Hi
I have a problem that is driving me crazy.
I have a fairly simple struts web app with a jsp form that submits to a
form bean, with an action set up and a display page. I have built a few
struts apps and never had such a basic problem:
The jsp submits the data and the form bean recieves it. It then
processes it correctly when the appropriate method is called from the
action (with the form cast in). I have debugged up to this point and so
know that everything is correct.
What should happen next is that my display page is shown and accesses my
form bean using the getters to retrieve the appropriate data values.
However when the action calls findforward, and the display page is
called, it seems to create a new instance of my form bean and so all
data values are null.
Any ideas?
My code on the display jsp is:
<%@ page language="java"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/taglibs-datetime.tld" prefix="dt" %>
<%@ taglib uri="/WEB-INF/displaytag_1_0.tld" prefix="display" %>
<jsp:useBean id="apacheConnectionStats" scope="session"
class="com.ftid.mis.form.apache_connection_stats" />
<html>
<head><title>JSP Page</title></head>
<body>
Well done
<br>
<%= apacheConnectionStats.getSql_stmt() %>
</body>
</html>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Loosing my form bean instance...
Posted by Brett <br...@thebault.co.uk>.
Problem solved.
The issue was, as Hubert pointed out, the mismatch in naming between my
JSP useBean and my struts-config formbean tags. I actually never
realised they need be the same, i thought the id in useBean simply gave
a name of an instance to use for the rest of the jsp.
The reason i use a temporary form object is so I can cast the form into
an object with the correct methods to call.
Brett
Martin Gainty wrote:
> Is there a reason why you are creating a temporary form object in your
> execute instead of using the original?
> M-
> ----- Original Message ----- From: "Hubert Rabago" <hr...@gmail.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Tuesday, July 12, 2005 8:59 AM
> Subject: Re: Loosing my form bean instance...
>
>
> In that case, it'd be the case mismatch between what your JSP is
> looking for and how your form is configured in struts-config.xml:
>
> <jsp:useBean id="apacheConnectionStats" scope="session"
> class="com.ftid.mis.form.apache_connection_stats" />
>
> <form-bean name="ApacheConnectionStats"
> type="com.ftid.mis.form.apache_connection_stats" />
>
> Hubert
>
> On 7/12/05, Brett <br...@thebault.co.uk> wrote:
>
>> Apologies
>>
>> The session and request scope discrepency was in there by mistake - that
>> was me debugging. Originally all was set to request. Unfortunatley it
>> makes no difference whether it is all set to request or session.
>>
>> So it's something else!
>>
>> Brett
>>
>> Hubert Rabago wrote:
>> > The form you're populating in your action is not the same instance
>> > you're accessing in your JSP. Your JSP is looking for the form in
>> > session scope, but you've configured your action to receive its form
>> > in request scope, so you're actually using two forms. Remove the
>> > 'scope="request"' in the "/apache_connection_stats" so it'll use the
>> > default session scope and match what you're expecting in your JSP, or
>> > change your JSP to look for the form in request scope.
>> >
>> > Hubert
>> >
>> > On 7/12/05, Brett <br...@thebault.co.uk> wrote:
>> >
>> >><action-mappings>
>> >> <action
>> >> path="/apache_connection_stats"
>> >> type="com.ftid.mis.action.MisAction"
>> >> name="ApacheConnectionStats"
>> >> scope="request">
>> >> <forward name="success" path="/pages/display.jsp" />
>> >> </action>
>> >>...
>> >></action-mappings>
>> >>
>> >>Action:
>> >>public ActionForward execute(ActionMapping mapping, ActionForm form,
>> >> HttpServletRequest request, HttpServletResponse
>> response) {
>> >>
>> >> apache_connection_stats tempform =
>> (apache_connection_stats) >> form;
>> >>
>> >
>> >
>> > ---------------------------------------------------------------------
>> > 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
>
>
> ---------------------------------------------------------------------
> 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: Loosing my form bean instance...
Posted by Martin Gainty <mg...@hotmail.com>.
Is there a reason why you are creating a temporary form object in your
execute instead of using the original?
M-
----- Original Message -----
From: "Hubert Rabago" <hr...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, July 12, 2005 8:59 AM
Subject: Re: Loosing my form bean instance...
In that case, it'd be the case mismatch between what your JSP is
looking for and how your form is configured in struts-config.xml:
<jsp:useBean id="apacheConnectionStats" scope="session"
class="com.ftid.mis.form.apache_connection_stats" />
<form-bean name="ApacheConnectionStats"
type="com.ftid.mis.form.apache_connection_stats" />
Hubert
On 7/12/05, Brett <br...@thebault.co.uk> wrote:
> Apologies
>
> The session and request scope discrepency was in there by mistake - that
> was me debugging. Originally all was set to request. Unfortunatley it
> makes no difference whether it is all set to request or session.
>
> So it's something else!
>
> Brett
>
> Hubert Rabago wrote:
> > The form you're populating in your action is not the same instance
> > you're accessing in your JSP. Your JSP is looking for the form in
> > session scope, but you've configured your action to receive its form
> > in request scope, so you're actually using two forms. Remove the
> > 'scope="request"' in the "/apache_connection_stats" so it'll use the
> > default session scope and match what you're expecting in your JSP, or
> > change your JSP to look for the form in request scope.
> >
> > Hubert
> >
> > On 7/12/05, Brett <br...@thebault.co.uk> wrote:
> >
> >><action-mappings>
> >> <action
> >> path="/apache_connection_stats"
> >> type="com.ftid.mis.action.MisAction"
> >> name="ApacheConnectionStats"
> >> scope="request">
> >> <forward name="success" path="/pages/display.jsp" />
> >> </action>
> >>...
> >></action-mappings>
> >>
> >>Action:
> >>public ActionForward execute(ActionMapping mapping, ActionForm form,
> >> HttpServletRequest request, HttpServletResponse response) {
> >>
> >> apache_connection_stats tempform = (apache_connection_stats)
> >> form;
> >>
> >
> >
> > ---------------------------------------------------------------------
> > 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
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Loosing my form bean instance...
Posted by Hubert Rabago <hr...@gmail.com>.
In that case, it'd be the case mismatch between what your JSP is
looking for and how your form is configured in struts-config.xml:
<jsp:useBean id="apacheConnectionStats" scope="session"
class="com.ftid.mis.form.apache_connection_stats" />
<form-bean name="ApacheConnectionStats"
type="com.ftid.mis.form.apache_connection_stats" />
Hubert
On 7/12/05, Brett <br...@thebault.co.uk> wrote:
> Apologies
>
> The session and request scope discrepency was in there by mistake - that
> was me debugging. Originally all was set to request. Unfortunatley it
> makes no difference whether it is all set to request or session.
>
> So it's something else!
>
> Brett
>
> Hubert Rabago wrote:
> > The form you're populating in your action is not the same instance
> > you're accessing in your JSP. Your JSP is looking for the form in
> > session scope, but you've configured your action to receive its form
> > in request scope, so you're actually using two forms. Remove the
> > 'scope="request"' in the "/apache_connection_stats" so it'll use the
> > default session scope and match what you're expecting in your JSP, or
> > change your JSP to look for the form in request scope.
> >
> > Hubert
> >
> > On 7/12/05, Brett <br...@thebault.co.uk> wrote:
> >
> >><action-mappings>
> >> <action
> >> path="/apache_connection_stats"
> >> type="com.ftid.mis.action.MisAction"
> >> name="ApacheConnectionStats"
> >> scope="request">
> >> <forward name="success" path="/pages/display.jsp" />
> >> </action>
> >>...
> >></action-mappings>
> >>
> >>Action:
> >>public ActionForward execute(ActionMapping mapping, ActionForm form,
> >> HttpServletRequest request, HttpServletResponse response) {
> >>
> >> apache_connection_stats tempform = (apache_connection_stats) form;
> >>
> >
> >
> > ---------------------------------------------------------------------
> > 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: Loosing my form bean instance...
Posted by Brett <br...@thebault.co.uk>.
Apologies
The session and request scope discrepency was in there by mistake - that
was me debugging. Originally all was set to request. Unfortunatley it
makes no difference whether it is all set to request or session.
So it's something else!
Brett
Hubert Rabago wrote:
> The form you're populating in your action is not the same instance
> you're accessing in your JSP. Your JSP is looking for the form in
> session scope, but you've configured your action to receive its form
> in request scope, so you're actually using two forms. Remove the
> 'scope="request"' in the "/apache_connection_stats" so it'll use the
> default session scope and match what you're expecting in your JSP, or
> change your JSP to look for the form in request scope.
>
> Hubert
>
> On 7/12/05, Brett <br...@thebault.co.uk> wrote:
>
>><action-mappings>
>> <action
>> path="/apache_connection_stats"
>> type="com.ftid.mis.action.MisAction"
>> name="ApacheConnectionStats"
>> scope="request">
>> <forward name="success" path="/pages/display.jsp" />
>> </action>
>>...
>></action-mappings>
>>
>>Action:
>>public ActionForward execute(ActionMapping mapping, ActionForm form,
>> HttpServletRequest request, HttpServletResponse response) {
>>
>> apache_connection_stats tempform = (apache_connection_stats) form;
>>
>
>
> ---------------------------------------------------------------------
> 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: Loosing my form bean instance...
Posted by Hubert Rabago <hr...@gmail.com>.
The form you're populating in your action is not the same instance
you're accessing in your JSP. Your JSP is looking for the form in
session scope, but you've configured your action to receive its form
in request scope, so you're actually using two forms. Remove the
'scope="request"' in the "/apache_connection_stats" so it'll use the
default session scope and match what you're expecting in your JSP, or
change your JSP to look for the form in request scope.
Hubert
On 7/12/05, Brett <br...@thebault.co.uk> wrote:
>
> <action-mappings>
> <action
> path="/apache_connection_stats"
> type="com.ftid.mis.action.MisAction"
> name="ApacheConnectionStats"
> scope="request">
> <forward name="success" path="/pages/display.jsp" />
> </action>
> ...
> </action-mappings>
>
> Action:
> public ActionForward execute(ActionMapping mapping, ActionForm form,
> HttpServletRequest request, HttpServletResponse response) {
>
> apache_connection_stats tempform = (apache_connection_stats) form;
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Loosing my form bean instance...
Posted by Brett <br...@thebault.co.uk>.
Sure:
/**
* Getter for property sql_stmt.
* @return Value of property sql_stmt.
*/
public String getSql_stmt() {
return this.sql_stmt;
}
However this is not the problem. I have tried many different getters and
indeed in the debugger I have looked at the variables on the bean being
used by the display jsp. The problem is that the display jsp is using a
new instance of apache_connection_stats, but I want it to use the
instance populated by the form...
I really don't know where i have gone wrong. Below is the applicable
code for my struts-config and Action:
Struts config:
<form-beans>
<form-bean name="ApacheConnectionStats"
type="com.ftid.mis.form.apache_connection_stats" />
...
</form-beans>
<action-mappings>
<action
path="/apache_connection_stats"
type="com.ftid.mis.action.MisAction"
name="ApacheConnectionStats"
scope="request">
<forward name="success" path="/pages/display.jsp" />
</action>
...
</action-mappings>
Action:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
apache_connection_stats tempform = (apache_connection_stats) form;
tempform.doSql(this.getDataSource(request, "FTID"),
this.getDataSource(request, "FTIDLOGS"));
String moo = tempform.getSql_stmt();
return mapping.findForward("success");
}
Note: the string 'moo' does indeed contain the correct sql_stmt as
constructed by the form bean
Martin Gainty wrote:
> Brett-
> Can we see the code for your Bean
> com.ftid.mis.form.apache_connection_stats ?
> specifically the getSql_stmt() method ?
> Martin-
> ----- Original Message ----- From: "Brett" <br...@thebault.co.uk>
> To: <us...@struts.apache.org>; <th...@ftid.com>
> Sent: Tuesday, July 12, 2005 7:23 AM
> Subject: Loosing my form bean instance...
>
>
>> Hi
>>
>> I have a problem that is driving me crazy.
>>
>> I have a fairly simple struts web app with a jsp form that submits to
>> a form bean, with an action set up and a display page. I have built a
>> few struts apps and never had such a basic problem:
>>
>> The jsp submits the data and the form bean recieves it. It then
>> processes it correctly when the appropriate method is called from the
>> action (with the form cast in). I have debugged up to this point and
>> so know that everything is correct.
>>
>> What should happen next is that my display page is shown and accesses
>> my form bean using the getters to retrieve the appropriate data
>> values. However when the action calls findforward, and the display
>> page is called, it seems to create a new instance of my form bean and
>> so all data values are null.
>>
>> Any ideas?
>>
>> My code on the display jsp is:
>>
>> <%@ page language="java"%>
>>
>> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
>> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
>> <%@ taglib uri="/WEB-INF/taglibs-datetime.tld" prefix="dt" %>
>> <%@ taglib uri="/WEB-INF/displaytag_1_0.tld" prefix="display" %>
>>
>> <jsp:useBean id="apacheConnectionStats" scope="session"
>> class="com.ftid.mis.form.apache_connection_stats" />
>>
>> <html>
>> <head><title>JSP Page</title></head>
>> <body>
>>
>> Well done
>> <br>
>> <%= apacheConnectionStats.getSql_stmt() %>
>> </body>
>> </html>
>>
>> ---------------------------------------------------------------------
>> 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: Loosing my form bean instance...
Posted by Martin Gainty <mg...@hotmail.com>.
Brett-
Can we see the code for your Bean com.ftid.mis.form.apache_connection_stats
?
specifically the getSql_stmt() method ?
Martin-
----- Original Message -----
From: "Brett" <br...@thebault.co.uk>
To: <us...@struts.apache.org>; <th...@ftid.com>
Sent: Tuesday, July 12, 2005 7:23 AM
Subject: Loosing my form bean instance...
> Hi
>
> I have a problem that is driving me crazy.
>
> I have a fairly simple struts web app with a jsp form that submits to a
> form bean, with an action set up and a display page. I have built a few
> struts apps and never had such a basic problem:
>
> The jsp submits the data and the form bean recieves it. It then processes
> it correctly when the appropriate method is called from the action (with
> the form cast in). I have debugged up to this point and so know that
> everything is correct.
>
> What should happen next is that my display page is shown and accesses my
> form bean using the getters to retrieve the appropriate data values.
> However when the action calls findforward, and the display page is called,
> it seems to create a new instance of my form bean and so all data values
> are null.
>
> Any ideas?
>
> My code on the display jsp is:
>
> <%@ page language="java"%>
>
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
> <%@ taglib uri="/WEB-INF/taglibs-datetime.tld" prefix="dt" %>
> <%@ taglib uri="/WEB-INF/displaytag_1_0.tld" prefix="display" %>
>
> <jsp:useBean id="apacheConnectionStats" scope="session"
> class="com.ftid.mis.form.apache_connection_stats" />
>
> <html>
> <head><title>JSP Page</title></head>
> <body>
>
> Well done
> <br>
> <%= apacheConnectionStats.getSql_stmt() %>
> </body>
> </html>
>
> ---------------------------------------------------------------------
> 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: Loosing my form bean instance...
Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Brett" <br...@thebault.co.uk>
> What should happen next is that my display page is shown and accesses my
> form bean using the getters to retrieve the appropriate data values.
> However when the action calls findforward, and the display page is called,
> it seems to create a new instance of my form bean and so all data values
> are null.
>
> <%= apacheConnectionStats.getSql_stmt() %>
Is 'apacheConnectionStats' the name of the form bean?
Look for a redirect somewhere... assuming the form is in request scope,
redirecting (rather than forwarding) will cause the browser to send a new
request, and you'll lose everything in the old one. To test for this, put
the form in session scope and see if the problem goes away.
Post the relevant parts of struts-config.xml and your Action if you need
more help.
--
Wendy Smoak
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org