Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java 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
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Advice on first project

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first project using Struts and starting with version 2. This is part of a form I'm building to add a user to a database and my first attempt at implementing Struts2 in a web application. This is how I'm pulling the data from the database to fill options for select fields. I've read about using DAO to keep the query results from the database abstracted so the front end doesn't care where the data is coming from.
I think I've got a basic handle on how things with Struts works, but just wanted to make sure I'm going on the right path before I continue further. Appreciate any advice at all. Thanks!

DAOBase.java


City.java


CityDAO.java


AddOwnerForm.java


struts.xml


form.jsp
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haven't done raw JDBC for... a really long time, but it seems okay. Does it work?I'd just do:I'm all for comments, but comments that are essentially identical to the code are just meaningless noise.

The other issue is that your action *is* caring about where the data comes from because you're tied directly to your DAO implementation. So while the *idea* is sound, the implementation does nothing to avoid the ultimate issue.

There are several ways around this, but if you're just starting out it might be best to avoid any further complication for now. If you want to pursue it further I'd consider looking at the Spring plugin. Spring also has a *lot* of convenient functionality that can wrap up the JDBC code.
 
Keith Fiske
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, everything is working. I'm just kinda checking if I'm going on the right path before I continue further. I'd started over from scratch several times as I learned JSP, starting first using just plain JSTL, then learning how to write servlets & tags, then learning that most Java web apps have moved onto using things like Struts where a lot of this is already wrapped up nicely in an API. It seems I'm almost caught up with how modern JSP development is done, I just wanted to double-check again just in case.

I thought the abstraction between the database & front end was just getting the data formatted to a point that was native to Java (Lists in this case) for the Actions to use. Didn't know it was supposed to go further than that.

I'd read briefly about Spring/Hibernate, but I wasn't sure if I should pursue it with this. Maybe I will now.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I thought the abstraction between the database & front end was just getting the data formatted to a point that was native to Java (Lists in this case) for the Actions to use. Didn't know it was supposed to go further than that.


You're definitely right about that--you don't really want to be passing ResultSets around or anything.

How far to take decoupling really depends on a lot of things and your general programming philosoph[y|ies], and is pretty off-topic to this forum. Check out "Inversion of Control" and/or "Dependency Injection" resources--they'll explain the level I'm talking about here.

There's nothing intrinsically wrong with what you've done--don't get me wrong :)
 
Keith Fiske
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great! Appreciate your time looking over my work so far!
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No sweat. I was just in a heavy mentoring phase, so I'm used to it ;)
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!