Solved

Struts - Cannot find bean error

Posted on 2004-08-31
19
889 Views
Last Modified: 2013-12-29
I am getting:

javax.servlet.ServletException: Cannot find bean DateRange in any scope


My Action Class (ShowKalendarList.java) is:
---------------------------------------------------

public ActionForward execute( ActionMapping mapping,
                                                    ActionForm form,
                                                  HttpServletRequest request,
                                                  HttpServletResponse response) throws Exception {
            
            
            try {
                  Context context = new InitialContext();
                  ListSessionHome home = (ListSessionHome)context.lookup(ListSessionHome.JNDI_NAME);
                  ListSession local = home.create();
                  
                  PeriodeSessionHome periodeSessionHome = (PeriodeSessionHome)context.lookup(PeriodeSessionHome.JNDI_NAME);
                  PeriodeSession periodeSession = periodeSessionHome.create();
                                          
                  System.out.println("------------------");
                  
                  GregorianCalendar from = new GregorianCalendar();
                  from.set(2003,9,20,0,0,0);
                  GregorianCalendar to = new GregorianCalendar();
                  to.set(2003,9,23,0,0,0);
                  
                  System.out.println(from.getTime());
                  System.out.println(to.getTime());
                  
                  /* set it in the request */
                  request.setAttribute("DateRange", periodeSession.getPeriodeByDateRange(from.getTime(), to.getTime()));
                  
            }
            catch (NamingException e) {
                  e.printStackTrace();
            }
            catch (CreateException e) {
                  e.printStackTrace();
            }      
            
            
            return mapping.findForward("Default");
      }


and In my show_kalendar_list.jsp, I have:
--------------------------------------------------

      <logic:iterate name="DateRange" id="Date">
                              <td> <bean:write name="Date" property="label" /> </td>
                        </logic:iterate>


In my Struts-config.xml, I have:
--------------------------------------

 <action path="/ShowKalendarList" type="de.grassgmbh.kalendartool.action.ShowKalendarList">
         <forward name="Default" path="/jsp/manage_list/show_kalendar_list.jsp" />
      </action>

Thanks.
0
Comment
Question by:sangeetha
  • 8
  • 6
  • 5
19 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11940429
What happens if you add the DateRange in the session? Can you still not retrieve it in the next page?
0
 
LVL 35

Accepted Solution

by:
TimYates earned 95 total points
ID: 11940465
afaik....this should work :-/
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11940466
yes, same result.
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 95 total points
ID: 11940481
I assume it does print out your debug (so the action is running)?
0
 
LVL 35

Expert Comment

by:girionis
ID: 11940493
With session? Try this:

/* set it in the session */
HttpSession session = request.getSession(false);
session.setAttrigute("DateRange", periodeSession.getPeriodeByDateRange(from.getTime(), to.getTime()));

and in your show_kalendar_list.jsp, do:

Object o = session.getAttribute("DateRange");
System.out.println(o);

Tell us if "o" is null.
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11940497
oops...i think action is not running...

>> System.out.println("------------------");

even doesn't show in my console. !
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11940503
i get

12:58:33,289 ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Cannot find bean ListView in any scope
................
................

in my console.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11940510
Ahhhh...ok...

Where do you use "ListView" in your code?
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11940527
sorry...'ListView' is another bean. I actually get:

13:02:47,210 ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Cannot find bean DateRange in any scope

and so on.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 35

Assisted Solution

by:girionis
girionis earned 30 total points
ID: 11940542
If action is not running you cannot pass the beans around unless you do it from somewhere else.
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11940554
yes, i understand. Could you guess why my 'jsp' that has the 'action' in struts-config.xml doesn't running..
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 95 total points
ID: 11940564
You are going to "ShowKalendarList.do" aren't you?  Not straight to the jsp?
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11940613
nope! I accessed the 'jsp'

If i access "ShowKalendarList.do", i get:

javax.servlet.ServletException: No getter method for property  of bean DateRange
............
............

Thanks for your patience.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11940646
Can you show us the code of the DateRange and what property is missing the getter?
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11940696

public class PeriodeSession implements SessionBean {

/**
      * @author ws 26.08.2004
      * Return a periode array over date range
      *
      * @ejb.interface-method view-type = "both"
      *
      * @return PeriodeView[]
      */
      public PeriodeView[] getPeriodeByDateRange(Date from, Date to){
            
            Calendar calendar = Calendar.getInstance();
            Calendar calendarTemp = Calendar.getInstance();
            ArrayList arrayList = new ArrayList();
            DateFormat df = DateFormat.getDateInstance();
            
            /* WS 26.08.2004
             * Set calendar with date from
             */
            calendar.setTime(from);
            
            /* WS 26.08.2004
             * add one day to from date until the from date is equal to date
             */
            while(calendar.getTime().before(to) || calendar.getTime().equals(to)){
                  
                  PeriodeView periodeView = new PeriodeView();
                  
                  /* WS 26.08.2004
                   * Fill the periode object
                   */
                  calendarTemp.setTime(calendar.getTime());
                  calendarTemp.add(Calendar.MINUTE, 1440);
                  periodeView.setDateFrom(calendar.getTime());
                  periodeView.setDateTo(calendarTemp.getTime());
                  periodeView.setLabel(df.format(calendar.getTime()));
                  
                  arrayList.add(periodeView);
                                    
                  calendar.add(Calendar.DATE, 1);
            }
            
            return (PeriodeView[])arrayList.toArray(new PeriodeView[0]);
      }
      
 ...............................
 ...............................
 ...............................

and my PeriodeView contains all the getter, setter for the variables.

But, i think the problem might be different, as it worked yesterday!
0
 
LVL 35

Expert Comment

by:girionis
ID: 11940728
> But, i think the problem might be different, as it worked yesterday!

What have you changed since yesterday?
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11941127
>> What have you changed since yesterday?

yes, i got it. I have seperate 'Struts' and EJB projects. The mistake was: I didnt made Project-References for them.

I dont know when i will stop wasting time for these silly errors.

Anyhow, i learnt something from you in this Q. Thanks for your patience.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11941149
Yay!  Glad you got it sorted :-)

This sort of thing, just chatting with people sometimes helps you solve it ;-)

Good luck with it!!

Tim
0
 
LVL 35

Expert Comment

by:girionis
ID: 11941259
:)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now