Solved

Struts - Cannot find bean error

Posted on 2004-08-31
19
898 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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
 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 79
mockito example issue 8 72
Java Options in Zimbra Server 2 50
print map entry 34 67
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

776 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