You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Hanen Ben Rhouma <ha...@gmail.com> on 2009/08/27 12:30:14 UTC

Cannot find bean: "xxxx" in any scope

Hello there,

Please I have a blocking point which on which I've spent two days with no
light at the end if tunnel:

Actually I've declared my bean into struts-config.xml like this:

<action
            path="/users"
            id="users"
            scope="request"
            name="users"
            type="com.myapp.struts.UsersAction"
            parameter="/users.jsp">
</action>

after that I tried to invoke this bean's method so I wrote in my users.jsp
page:

<bean:write name="users" property="env"/>

when running my application it throws this exception:

javax.servlet.jsp.JspException: Cannot find bean: "users" in any scope
    org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:864)
    org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:233)

org.apache.jsp.users_jsp._jspx_meth_bean_005fwrite_005f0(users_jsp.java:158)
    org.apache.jsp.users_jsp._jspService(users_jsp.java:112)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


What's wrong in my bean declaration that hides it from being injected into
my application context???


Thanks in advance for any suggestion,
Hanen

Re: Cannot find bean: "xxxx" in any scope

Posted by Paweł Wielgus <po...@gmail.com>.
Hi Hanen,
i have no clue if that what You have done is ok (long time off struts1),
but a typical action definition in struts-config.xml looks like this:
<action name="regionsEditForm"
        path="/admin/regions/edit"
        type="com.pi.eplatform.suirz.user.action.admin.EditRegionsAction">
            <forward name="editRegions"
                         path="suirz.admin.regions.edit"/>
</action>

and i don't know if You are confusing beans with actions maybe? I also
don't know if by adding id attribute to action one makes them
automaticaly accessible as bean in page scope - but all of this should
be in docs.

Best greetings,
Paweł Wielgus.


2009/8/27 Hanen Ben Rhouma <ha...@gmail.com>:
> Hello there,
>
> Please I have a blocking point which on which I've spent two days with no
> light at the end if tunnel:
>
> Actually I've declared my bean into struts-config.xml like this:
>
> <action
>            path="/users"
>            id="users"
>            scope="request"
>            name="users"
>            type="com.myapp.struts.UsersAction"
>            parameter="/users.jsp">
> </action>
>
> after that I tried to invoke this bean's method so I wrote in my users.jsp
> page:
>
> <bean:write name="users" property="env"/>
>
> when running my application it throws this exception:
>
> javax.servlet.jsp.JspException: Cannot find bean: "users" in any scope
>    org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:864)
>    org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:233)
>
> org.apache.jsp.users_jsp._jspx_meth_bean_005fwrite_005f0(users_jsp.java:158)
>    org.apache.jsp.users_jsp._jspService(users_jsp.java:112)
>    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
>    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
>    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
>    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>
>
> What's wrong in my bean declaration that hides it from being injected into
> my application context???
>
>
> Thanks in advance for any suggestion,
> Hanen
>

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


Re: Cannot find bean: "xxxx" in any scope

Posted by Paweł Wielgus <po...@gmail.com>.
Hi Hanen,
i don't think there is a simple answear to this question,
some say you should and some of us use only one (or few) forms in whole app,
every solution has it's own problems and limitations.
Also there is another question if to use session or request form,
which also has many answers (usability vs security).

But one thing is for sure, yes You have to use form in action.
You can also read some info about dynaforms.

Best greetings,
Paweł Wielgus.


2009/8/27 Hanen Ben Rhouma <ha...@gmail.com>:
> Thankyou Guys for your answers,
>
> In fact, I thought that using ActionForm isn't compulsory to inject beans
> result into jsp pages.
> Did that mean that I have to create an ActionForm for each Action i create
> and call it in my execute method?
>
> Kind Regards,
> Hanen
>
> On Thu, Aug 27, 2009 at 12:24 PM, Lukasz Lenart <
> lukasz.lenart@googlemail.com> wrote:
>
>> 2009/8/27 Hanen Ben Rhouma <ha...@gmail.com>:
>> > <action
>> >            path="/users"
>> >            id="users"
>> >            scope="request"
>> >            name="users"
>> >            type="com.myapp.struts.UsersAction"
>> >            parameter="/users.jsp">
>> > </action>
>>
>> Did you define form-bean with name "users"? Instead using name="users"
>> in action is better to use name="usersForm" and define form beans as
>> follow
>>
>> <form-beans>
>>        <form-bean name="usersForm" type="org.demo.web.UsersForm"/>
>> </form-beans>
>>
>>
>> Regards
>> --
>> Lukasz
>> http://www.lenart.org.pl/
>> http://dailylog.lenart.org.pl/
>>
>> ---------------------------------------------------------------------
>> 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: Cannot find bean: "xxxx" in any scope

Posted by Hanen Ben Rhouma <ha...@gmail.com>.
Thankyou Guys for your answers,

In fact, I thought that using ActionForm isn't compulsory to inject beans
result into jsp pages.
Did that mean that I have to create an ActionForm for each Action i create
and call it in my execute method?

Kind Regards,
Hanen

On Thu, Aug 27, 2009 at 12:24 PM, Lukasz Lenart <
lukasz.lenart@googlemail.com> wrote:

> 2009/8/27 Hanen Ben Rhouma <ha...@gmail.com>:
> > <action
> >            path="/users"
> >            id="users"
> >            scope="request"
> >            name="users"
> >            type="com.myapp.struts.UsersAction"
> >            parameter="/users.jsp">
> > </action>
>
> Did you define form-bean with name "users"? Instead using name="users"
> in action is better to use name="usersForm" and define form beans as
> follow
>
> <form-beans>
>        <form-bean name="usersForm" type="org.demo.web.UsersForm"/>
> </form-beans>
>
>
> Regards
> --
> Lukasz
> http://www.lenart.org.pl/
> http://dailylog.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Cannot find bean: "xxxx" in any scope

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/8/27 Hanen Ben Rhouma <ha...@gmail.com>:
> <action
>            path="/users"
>            id="users"
>            scope="request"
>            name="users"
>            type="com.myapp.struts.UsersAction"
>            parameter="/users.jsp">
> </action>

Did you define form-bean with name "users"? Instead using name="users"
in action is better to use name="usersForm" and define form beans as
follow

<form-beans>
        <form-bean name="usersForm" type="org.demo.web.UsersForm"/>
</form-beans>


Regards
-- 
Lukasz
http://www.lenart.org.pl/
http://dailylog.lenart.org.pl/

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