• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I Call a Bean Function Using JSP?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to call my Bean's method, but I don't know how to do that without using EL. I don't want to use EL because it's bad coding practice.



 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lindz Zdnil wrote:I need to call my Bean's method, but I don't know how to do that without using EL. I don't want to use EL because it's bad coding practice.


You've got two things wrong:
  • You cannot use the EL to call general bean methods. Only bean properties can be accessed.
  • Using the EL is most certainly not a bad coding procatce -- quite the opposite. The EL is the preferred way to add dynamic data to JSPs. Who told you that?
  •  
    Lindsay Fester
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I meant using <% %> with straight Java code, not EL. So how would I call a method? I'm new to JSP and having a lot of trouble with my assignment.
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you need to call a bean method, it's a sign of a design problem. Either you are trying to do something in the JSP that should be handled by the page controller, or your bean has a design problem. Beans should have getters and setters -- general methods violate the bean pattern.
     
    Lindsay Fester
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Basically I have an assignment where I need to create a dynamic table that represents a time sheet. Employees can login, makes changes to time sheets, and save them to the remote database. Employees can also click "Add a Row" to add a new row to the time sheet. So I've created a bean to represent the table with an 2D array list of TSCells. Each TSCell object has coordinates (as an ID) and data. In the JSP page, I create and populate an HTML table filled with text inputs.

    At the moment I'm having 2 issues:

    1. Saving to the column value because I can't figure out how access the TSCell's setData() method in JSP because it's in an ArrayList, there's no "bean" I can use for it. Is there a way to reference an existing bean? Can I use EL to access it?

    2. Every time I add a row by clicking the "Add Row" button, the form action sends the input to the "ts_process.jsp" page, which forwards back to the original. The row is added, but I can't add additional rows. I seem to be stuck on the ts_process.jsp page or something.

    3. I still can't find a way to call the bean method "Add Row" without using scriptlets (<% tags with pure Java). Is there a way? Or is it just poor design as you've said?

    I'm not looking for someone to do my assignment for me, I want to learn. I just can't seem to find specific answers to my questions online. So how would I go about solving these issues? Is it possible? Should I change my design from a table class to multiple objects (e.g. have time sheet entry objects with data members for each column)?
     
    Bartender
    Posts: 1111
    Eclipse IDE Oracle VI Editor
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    what are you learning in your course? have you been taught about servlets?
    as if i was doing it i would look into a form/servlet call for add row, but i am pretty new to this myself
     
    Lindsay Fester
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I'm calling this one solved. The only way to call a bean method is to use EL. As for the rest, I made some minor mistakes with my code that have been corrected (i.e. accidentally setting the scope to request instead of session).

    Thanks to all who replied.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic