aspose file tools*
The moose likes Struts and the fly likes Struts - Cannot find bean in any scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts - Cannot find bean in any scope" Watch "Struts - Cannot find bean in any scope" New topic
Author

Struts - Cannot find bean in any scope

Juan Matias Lopez
Greenhorn

Joined: Jul 31, 2011
Posts: 7
Hi, everyone. Im banging my head against the wall here. Im using Netbeans 7.0 to implement with the native Struts support an application to display a series of links in a page. Im getting the error:

HTTP Status 500 -
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "linkListForm" in any scope
root cause
javax.servlet.jsp.JspException: Cannot find bean: "linkListForm" in any scope

(using Glassfish Server 3.1, also native).

Ive checked a lot of sites and forums, and nothing seems to fix this.

My struts-config:



linkListAction:



LinkListForm:


and the jps that is giving the error:


I really dont know what to do. Im a newbie in Struts. If it helps, when I press "ctrol+click" on name="linkListForm" Netbeans says The file linkListForm was not found.

Thanks in advance!
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Jaun, since you are setting the list in session as below
mention scope="session" in all the places in JSP where ever it is being used. For example,
Anyways, why would you need overload your session with a list? why wont don't you use use request instead?
However, the above should work for you


Have Fun with Java
little,little.. little by little makes a lot..
Rajagopal Mani
Ranch Hand

Joined: Mar 24, 2011
Posts: 84

Hi Jaun, Please note the logical form-bean name & session attribute name are same which may lead fail. Remove the line where the collection links set in session scope & try.
Juan Matias Lopez
Greenhorn

Joined: Jul 31, 2011
Posts: 7
Thanks for the answers.

Shankar Tanikella wrote:Hi Jaun, since you are setting the list in session as below
mention scope="session" in all the places in JSP where ever it is being used. For example,
Anyways, why would you need overload your session with a list? why wont don't you use use request instead?
However, the above should work for you


I tried this, but it results in the same error:

type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "linkListForm" in scope: "session"
root cause
javax.servlet.jsp.JspException: Cannot find bean: "linkListForm" in scope: "session"

Could you give me an example using request? As I said, im not very familiar with this XD

Rajagopal Mani wrote:Hi Jaun, Please note the logical form-bean name & session attribute name are same which may lead fail. Remove the line where the collection links set in session scope & try.


Im not sure if I get this right, but I removed the line:
session.setAttribute("linkList", linklistform.getLinks());
and the error is the same.
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Ha, firstly use html:form in your JSP and try whatever you tried before using request, it would be similar to below code
Action ClassIn your JSPHope this time it works. again
Actually, you need not set the form in the request while using html:form
Juan Matias Lopez
Greenhorn

Joined: Jul 31, 2011
Posts: 7
Shankar Tanikella wrote:Ha, firstly use html:form in your JSP and try whatever you tried before using request, it would be similar to below code
Actually, you need not set the form in the request while using html:form


Thanks a lot! I finally could resolve that problem. Now, at least the page loads fine. But, as it seems to happen, new problems arised.

As I said, im trying to manipulate a collection of links. When I load that jsp, the collection apparently initiates empty. But I modified the listLinkAction and the container class (listaLinks) to add an element (for testing purposes). But the list always shows empty. I made several debbuging, and found out that the reset method of the form is used, but the execute() dont. I would be really glad if you could help me again XD

linklist.jsp


linkListAction(with several comments of the things I tried)


listaLink.java (again, a lot of comments, also, im not sure of the path for the file, that is, to keep and load the links)


Thanks a lot!
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Are you sure that execute method is not being called? anyways, try this piece of code in your action just to very what is happeningAnd to see the list size in your JSP add some text within the iterate tag and see if it is entering the loop(just in case)
Juan Matias Lopez
Greenhorn

Joined: Jul 31, 2011
Posts: 7
Shankar Tanikella wrote:Are you sure that execute method is not being called? anyways, try this piece of code in your action just to very what is happeningAnd to see the list size in your JSP add some text within the iterate tag and see if it is entering the loop(just in case)


Just tested it, the list is still "size=0".
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Interesting, Could you share the latest code snippets for
1. the method in action class
2. the form bean (if it is changed to the earlier)
3. the JSP code used to display
There is some small and silly thing that we are missing, we shall dig it this time
Juan Matias Lopez
Greenhorn

Joined: Jul 31, 2011
Posts: 7
Shankar Tanikella wrote:Interesting, Could you share the latest code snippets for
1. the method in action class
2. the form bean (if it is changed to the earlier)
3. the JSP code used to display
There is some small and silly thing that we are missing, we shall dig it this time


linkListAction:


linkListForm:


listalink.jsp:


Testing some things, we noticed that in a similar jsp/form/action (the one used to simulate a login) the execute() method is accesed after posting a <html:submit>. So, we are looking for a way to do this automatically, I think.

Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Good, 1. try changing the method name in the action class from 'execute' to something else and call this method in the input JSP.
2. extend DispatchAction instead of Action (not really sure, just give a try)
Juan Matias Lopez
Greenhorn

Joined: Jul 31, 2011
Posts: 7
The second option didnt work. The first one... Im not really sure who to call that renamed method. Anyway, I dont really think thats the good way to go XD Thanks for the ideas.
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

One point to note is that the form reset method is called upon the request submission.

Anyways, just to add up, let us look into this scenario
1. You logged into the application (execute method is invoked),welcome screen is displayed with several links
2. you click on one of the links (a) or button (b)
(a) link: you would provide some URL for redirection, say for example: http://mysite.com/SecondPage.do
(b) button: you would handle the destination of submit in a JS(?). For this you would provide form.action=http://mysite.com/SecondPage.do
3. (in both the scenarios a,b you would execute using 'execute' method itself) The destination page (say your links page) is displayed after processing

now we shall change this using parameter,
in the struts config you have posted earlier we also have an option to add "parameter" attribute in the action mapping section. normally we use the parameter as method. we can give any name for that matter(even my name), for example this makes you to call several methods in the same action class, how?
Going back to the 2.b you provide the action for form submission form.action=http://mysite.com/SecondPage.do?method=someMethodNameInSameAction
So then it would verify the "/SecondPage" action path and execute the method named 'someMethodNameInSameAction'. However, if you feel that using methods is not the good way to go, then, we would end up creating a separate action class for each functionality we have, isn't it?
Juan Matias Lopez
Greenhorn

Joined: Jul 31, 2011
Posts: 7
On a second thought, im running out of ideas XD
I tried your suggestion, same result.







However, im not sure if the syntax is right.
Anyway, this is not working either. You said something about making addicional Action classes, what for? Anyway, thanks for the help! (again)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts - Cannot find bean in any scope