Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Instantiate object without scriptlet

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I want to remove scriptlet from JSP page below.

But How I can instantiate DepartmentDTO using EL and JSTL?

thanks all

 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the class has a nullary constructor, you could instantiate an instance using <jsp:useBean>. But it's much more common for object instances to be created in the page controller for the JSP.
[ May 28, 2007: Message edited by: Bear Bibeault ]
 
Anthony Karta
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
If the class has a nullary constructor, you could instantiate an instance using <jsp:useBean>. But it's much more common for object instances to be created in the page controller for the JSP.

[ May 28, 2007: Message edited by: Bear Bibeault ]



Thanks Bear for quick reply but...

- How I can call getList() using <jsp:useBean>?
- What is "page controller"? I don't use Struts. should I implements Listener and save Department object in attribute.

btw, I'm still newbies in these area. thanks again.
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Anthony Karta:

- How I can call getList() using <jsp:useBean>?



<jsp:useBean> will create the scoped variable. From that point, you'd use the EL to obtain properties, such as your list property.

- What is "page controller"? I don't use Struts.



You don't need to use bloatware like Struts to structure your app using the best-practice Model 2 pattern.

should I implements Listener and save Department object in attribute.



I have no idea what you mean by this, but don't make things needlessly complicated.
 
Anthony Karta
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips. I figure it out.

Originally posted by Bear Bibeault:


I have no idea what you mean by this, but don't make things needlessly complicated.



I meant, add a servlet as context listener to populate departmentDTO.

This JSP will be the first page invoked from browser, I don't have servlet for this page - how I can apply Model 2 (MVC) pattern then?

thanks again.

[ May 28, 2007: Message edited by: Anthony Karta ]
[ May 28, 2007: Message edited by: Anthony Karta ]
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There really isn't any concept of a "first page". Are you talking about the "welcome page" that is displayed when no specific page is specified in the URL? In modern servlet containers, that can be a servlet.
 
Anthony Karta
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
There really isn't any concept of a "first page". Are you talking about the "welcome page" that is displayed when no specific page is specified in the URL? In modern servlet containers, that can be a servlet.



Hi Bear,

by first page I meant is the form that generated by JSP (see my first post), only jsp, no servlet.

should I re-design it, so I have a controller servlet that populate the data, save it in request attribute and forward the view to JSP?

I think I'm getting your point.

thanks
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the page expects any sort of preparation -- such as the instatiation of data elements -- it should have a page controller that does the setup on its behalf.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic