• Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom Tag Accessing DB  RSS feed

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

I am trying to make use of the custom tag facilities provided by the JSP specs. I haven't use Custom tags before but rely solely on JSTL. But I think custom tag packs a lot of powers.

Question though, Is it considered a good design decision if we have a custom tag access the Database Layer and work on the data retrieve from that?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends.

If the customer tag code directly accesses the db: no.

If it delegates the db access to the Model layer: maybe.

What would accessing the db in a custom tag buy you that can't be had from accessing the Model from the controller?
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Reyes wrote:Hi,

I am trying to make use of the custom tag facilities provided by the JSP specs. I haven't use Custom tags before but rely solely on JSTL. But I think custom tag packs a lot of powers.

Question though, Is it considered a good design decision if we have a custom tag access the Database Layer and work on the data retrieve from that?

Thanks.


In general, try to avoid that. Instead, lookup the data you want and attach it to the appropriate scope in your controller. Then forward the request,response to the JSP.
 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would accessing the db in a custom tag buy you that can't be had from accessing the Model from the controller?

Hi Bear, This is just actually a trivial question. I am new to using custom tags file using java, I already tried using custom tag files in
some of my JSP component such as navigation/menu/footer and I just wanted to explore some of its use.



Hi Deepak, I do believe that this can be accomplished using the model layer only and plain JSTL.

Question though, Is there really, much good use of custom tags in the enterprise level when JSTL can handle much of the workload.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question though, Is there really, much good use of custom tags in the enterprise level when JSTL can handle much of the workload.


But is it even JSTL's job ? For example

You can...

write a JSP from a servlet. But it makes the servlet less maintainable.
write business logic inside a stored procedure and lock to a DB vendor
style HTML pages inside the HTML instead of using CSS.

These are examples of things that you can do, but probably should not. Calling a database from a JSP page falls under this category. How would your custom tag handle DB failures ? Why should a view contact a persistence ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!