Solved

Struts - Cannot find bean error

Posted on 2004-08-31
19
896 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 39
Java passing arguments (type error) 2 48
how to add new optional parameter to JSP 1 29
MySQL  on Tomcat 8 30
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

896 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

14 Experts available now in Live!

Get 1:1 Help Now