You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tobias Flohre <fl...@adesso.de> on 2002/12/22 15:08:51 UTC

cannot find bean error

Hello everybody,

I have a serious problem, I already looked up all the list but didn't get
any information helping me to solve it. I am new to struts, so maybe it is
a simple thing, please take a look!

I have an action mitarbeiterAuswahlShow filling a form bean
MitarbeiterAuswahlForm, here the parts of the struts-config.xml:

    <form-bean      name="mitarbeiterAuswahlForm"
                    type="de.adesso.aproda.forms.MitarbeiterAuswahlForm"/>

    <action    path="/mitarbeiterauswahlShow"
               type="de.adesso.aproda.actions.MitarbeiterauswahlShowAction"
               name="mitarbeiterAuswahlForm"
               scope="session"
               parameter="method">
      <forward name="show"                 path="/mitarbeiterauswahl.jsp"/>
    </action>

When the action is called, the code is processed (i have some
system.out.println in the action class, it looks good there). The server
tells me this:

2002-12-22 02:37:13 - path="" :action:  Storing instance under attribute
'mitarbeiterAuswahlForm' in scope 'session'

which sounds pretty good to me, too.
But when I want to access mitarbeiterauswahlForm in the jsp, I get this:

javax.servlet.ServletException: Cannot find bean mitarbeiterAuswahlForm in
scope session

What are possible reasons for this??


For further information I add some snippets from the action class and the
jsp:

    MitarbeiterAuswahlForm mitarbeiterAuswahlForm
= (MitarbeiterAuswahlForm)form;
...
    mitarbeiterAuswahlForm.setMitarbeiter (mitarbeiter);
    mitarbeiterAuswahlForm.setStudenten (studenten);
    return mapping.findForward("show");

I added this line:
    request.setAttribute("mitarbeiterAuswahlForm",mitarbeiterAuswahlForm);
in the action class, but it is not necessary to do this by myself, right?
struts should put in the scope, no?

and the jsp:
<bean:define id="mitarbeiterListe" name="mitarbeiterAuswahlForm" property
="mitarbeiter"/>
<html:select styleClass="textbox" size="1" tabindex="3" property
="mitarbeiterID">
<html:options collection="mitarbeiterListe" property="id" labelProperty
="name" />
</html:select>



Thanks for any help!!!

Tobias



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cannot find bean error

Posted by Mark <ma...@libero.it>.
If you're putting your mitarbeiterListe in the session you don't need to
instantiate your bean in the page (i.e. <bean:define etc).

If you want to put it in the session do this in your action class.

 session.setAttribute("mylist",mylist);

Or in the request depending on what you want...

Then get your list out of the session like you're doing.. You don't need to
worry aboy the <bean:define stuff unless your looking to get at a list or
something without making available in the request or session or something..


<html:options collection="mitarbeiterListe" property="id"
labelProperty="name" />

Hope this helps. mark


On 22-12-2002 15:08, "Tobias Flohre" <fl...@adesso.de> wrote:

> Hello everybody,
> 
> I have a serious problem, I already looked up all the list but didn't get
> any information helping me to solve it. I am new to struts, so maybe it is
> a simple thing, please take a look!
> 
> I have an action mitarbeiterAuswahlShow filling a form bean
> MitarbeiterAuswahlForm, here the parts of the struts-config.xml:
> 
>   <form-bean      name="mitarbeiterAuswahlForm"
>                   type="de.adesso.aproda.forms.MitarbeiterAuswahlForm"/>
> 
>   <action    path="/mitarbeiterauswahlShow"
>              type="de.adesso.aproda.actions.MitarbeiterauswahlShowAction"
>              name="mitarbeiterAuswahlForm"
>              scope="session"
>              parameter="method">
>     <forward name="show"                 path="/mitarbeiterauswahl.jsp"/>
>   </action>
> 
> When the action is called, the code is processed (i have some
> system.out.println in the action class, it looks good there). The server
> tells me this:
> 
> 2002-12-22 02:37:13 - path="" :action:  Storing instance under attribute
> 'mitarbeiterAuswahlForm' in scope 'session'
> 
> which sounds pretty good to me, too.
> But when I want to access mitarbeiterauswahlForm in the jsp, I get this:
> 
> javax.servlet.ServletException: Cannot find bean mitarbeiterAuswahlForm in
> scope session
> 
> What are possible reasons for this??
> 
> 
> For further information I add some snippets from the action class and the
> jsp:
> 
>   MitarbeiterAuswahlForm mitarbeiterAuswahlForm
> = (MitarbeiterAuswahlForm)form;
> ...
>   mitarbeiterAuswahlForm.setMitarbeiter (mitarbeiter);
>   mitarbeiterAuswahlForm.setStudenten (studenten);
>   return mapping.findForward("show");
> 
> I added this line:
>   request.setAttribute("mitarbeiterAuswahlForm",mitarbeiterAuswahlForm);
> in the action class, but it is not necessary to do this by myself, right?
> struts should put in the scope, no?
> 
> and the jsp:
> <bean:define id="mitarbeiterListe" name="mitarbeiterAuswahlForm" property
> ="mitarbeiter"/>
> <html:select styleClass="textbox" size="1" tabindex="3" property
> ="mitarbeiterID">
> <html:options collection="mitarbeiterListe" property="id" labelProperty
> ="name" />
> </html:select>
> 
> 
> 
> Thanks for any help!!!
> 
> Tobias
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cannot find bean error

Posted by Mark <ma...@libero.it>.
I've had more luck with the trust old useBean tag as well.. But if is in
your session or request you don't need to worry about useBEan or bean:define
or whatever...

I'm also having trouble understanding why you want to instantiate a form
bean in your jsp.. 

If your collection is in the session or request you don't have to GEEK
AROUND in your jsp.. This is after all what we are all trying to achieve
else we'd all be coding perl "right?"..

Anyway.. Only use the useBEan stuff, if the collection isn't in the session
or request or something. If your putting collections in you session and
using useBean's etc then you doing stuff twice and twice and geeky...

ActionClass

Request.setAttibute("mylist",mylist);

And then 

<html:options collection="mylist" etc />

Or if you don't want to do that and want to just get a collect from a bean
or something then

<jsp:useBEan class="com.acme.ListStuff" etc

<html:options collection="mylist"

But if jerome is suggesting that you do both, then I want to know who his
crack dealer is, cos I want some of the same....




On 22-12-2002 15:51, "Jerome Jacobsen" <je...@gentootech.com>
wrote:

> Hi Tobias,
> 
> What you are doing looks OK to me.  You are correct in that you do NOT need
> to do the following in your action:
>> I added this line:
>>     request.setAttribute("mitarbeiterAuswahlForm",mitarbeiterAuswahlForm);
> 
> The bean is already stored in the session by the framework before your
> action is called.
> 
> Without seeing the rest of your JSP it is difficult to tell why you are
> getting the error.  Try adding the following near the beggining of your JSP:
> 
> <jsp:useBean id = "mitarbeiterAuswahlForm"
> class="de.adesso.aproda.forms.MitarbeiterAuswahlForm"
> scope="session"/>
> 
> If that got rid of the problem then you may have been accessing the bean in
> the JSP via other standard JSP tags.
> 
> -Jerome
> 
> 
>> -----Original Message-----
>> From: Tobias Flohre [mailto:flohre@adesso.de]
>> Sent: Sunday, December 22, 2002 9:09 AM
>> To: struts-user@jakarta.apache.org
>> Subject: cannot find bean error
>> 
>> 
>> Hello everybody,
>> 
>> I have a serious problem, I already looked up all the list but didn't get
>> any information helping me to solve it. I am new to struts, so maybe it is
>> a simple thing, please take a look!
>> 
>> I have an action mitarbeiterAuswahlShow filling a form bean
>> MitarbeiterAuswahlForm, here the parts of the struts-config.xml:
>> 
>>     <form-bean      name="mitarbeiterAuswahlForm"
>>                     type="de.adesso.aproda.forms.MitarbeiterAuswahlForm"/>
>> 
>>     <action    path="/mitarbeiterauswahlShow"
>> 
>> type="de.adesso.aproda.actions.MitarbeiterauswahlShowAction"
>>                name="mitarbeiterAuswahlForm"
>>                scope="session"
>>                parameter="method">
>>       <forward name="show"
>> path="/mitarbeiterauswahl.jsp"/>
>>     </action>
>> 
>> When the action is called, the code is processed (i have some
>> system.out.println in the action class, it looks good there). The server
>> tells me this:
>> 
>> 2002-12-22 02:37:13 - path="" :action:  Storing instance under attribute
>> 'mitarbeiterAuswahlForm' in scope 'session'
>> 
>> which sounds pretty good to me, too.
>> But when I want to access mitarbeiterauswahlForm in the jsp, I get this:
>> 
>> javax.servlet.ServletException: Cannot find bean mitarbeiterAuswahlForm in
>> scope session
>> 
>> What are possible reasons for this??
>> 
>> 
>> For further information I add some snippets from the action class and the
>> jsp:
>> 
>>     MitarbeiterAuswahlForm mitarbeiterAuswahlForm
>> = (MitarbeiterAuswahlForm)form;
>> ...
>>     mitarbeiterAuswahlForm.setMitarbeiter (mitarbeiter);
>>     mitarbeiterAuswahlForm.setStudenten (studenten);
>>     return mapping.findForward("show");
>> 
>> I added this line:
>>     request.setAttribute("mitarbeiterAuswahlForm",mitarbeiterAuswahlForm);
>> in the action class, but it is not necessary to do this by myself, right?
>> struts should put in the scope, no?
>> 
>> and the jsp:
>> <bean:define id="mitarbeiterListe" name="mitarbeiterAuswahlForm" property
>> ="mitarbeiter"/>
>> <html:select styleClass="textbox" size="1" tabindex="3" property
>> ="mitarbeiterID">
>> <html:options collection="mitarbeiterListe" property="id" labelProperty
>> ="name" />
>> </html:select>
>> 
>> 
>> 
>> Thanks for any help!!!
>> 
>> Tobias
>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: cannot find bean error

Posted by Jerome Jacobsen <je...@gentootech.com>.
Hi Tobias,

What you are doing looks OK to me.  You are correct in that you do NOT need
to do the following in your action:
> I added this line:
>     request.setAttribute("mitarbeiterAuswahlForm",mitarbeiterAuswahlForm);

The bean is already stored in the session by the framework before your
action is called.

Without seeing the rest of your JSP it is difficult to tell why you are
getting the error.  Try adding the following near the beggining of your JSP:

<jsp:useBean id = "mitarbeiterAuswahlForm"
	class="de.adesso.aproda.forms.MitarbeiterAuswahlForm"
	scope="session"/>

If that got rid of the problem then you may have been accessing the bean in
the JSP via other standard JSP tags.

-Jerome


> -----Original Message-----
> From: Tobias Flohre [mailto:flohre@adesso.de]
> Sent: Sunday, December 22, 2002 9:09 AM
> To: struts-user@jakarta.apache.org
> Subject: cannot find bean error
>
>
> Hello everybody,
>
> I have a serious problem, I already looked up all the list but didn't get
> any information helping me to solve it. I am new to struts, so maybe it is
> a simple thing, please take a look!
>
> I have an action mitarbeiterAuswahlShow filling a form bean
> MitarbeiterAuswahlForm, here the parts of the struts-config.xml:
>
>     <form-bean      name="mitarbeiterAuswahlForm"
>                     type="de.adesso.aproda.forms.MitarbeiterAuswahlForm"/>
>
>     <action    path="/mitarbeiterauswahlShow"
>
> type="de.adesso.aproda.actions.MitarbeiterauswahlShowAction"
>                name="mitarbeiterAuswahlForm"
>                scope="session"
>                parameter="method">
>       <forward name="show"
> path="/mitarbeiterauswahl.jsp"/>
>     </action>
>
> When the action is called, the code is processed (i have some
> system.out.println in the action class, it looks good there). The server
> tells me this:
>
> 2002-12-22 02:37:13 - path="" :action:  Storing instance under attribute
> 'mitarbeiterAuswahlForm' in scope 'session'
>
> which sounds pretty good to me, too.
> But when I want to access mitarbeiterauswahlForm in the jsp, I get this:
>
> javax.servlet.ServletException: Cannot find bean mitarbeiterAuswahlForm in
> scope session
>
> What are possible reasons for this??
>
>
> For further information I add some snippets from the action class and the
> jsp:
>
>     MitarbeiterAuswahlForm mitarbeiterAuswahlForm
> = (MitarbeiterAuswahlForm)form;
> ...
>     mitarbeiterAuswahlForm.setMitarbeiter (mitarbeiter);
>     mitarbeiterAuswahlForm.setStudenten (studenten);
>     return mapping.findForward("show");
>
> I added this line:
>     request.setAttribute("mitarbeiterAuswahlForm",mitarbeiterAuswahlForm);
> in the action class, but it is not necessary to do this by myself, right?
> struts should put in the scope, no?
>
> and the jsp:
> <bean:define id="mitarbeiterListe" name="mitarbeiterAuswahlForm" property
> ="mitarbeiter"/>
> <html:select styleClass="textbox" size="1" tabindex="3" property
> ="mitarbeiterID">
> <html:options collection="mitarbeiterListe" property="id" labelProperty
> ="name" />
> </html:select>
>
>
>
> Thanks for any help!!!
>
> Tobias
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>