Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Instantiate object without scriptlet  RSS feed

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

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!