• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

First jsp and servlet application - help/suggestions/etc

 
Ranch Hand
Posts: 34
2
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm starting to learn jsp and servlet technology and I thought a good way was, apart from studying books (actually I'm using Murach and Budi Kurniawan ones), practice with some code.
This also to take some breaks from the last steps in OCPJP exam preparation which actually is giving me hard times.

Well, I decided to try to develop a web application related to some job requirements. The Company I work for has recently given the employees the possibility to work from home a couple of days per week.
My unit is managing such planning and approvals with excel files, so I thought it could have been a good opportunity to start with something real.

Some high level features the application will have in this very first step:
1 login form
2 insert new user planning (planning requests can be submitted until wednesday on the current week and cover the next two weeks)
3 manager approval/reject of user requests (approvals/reject can be done from thursday to friday of the current week related to the planning for the upcoming two weeks)
4 overall view of all users requests

What I've achieved so far is:
1) done (with a special attention for security related aspects, not because the application manages sensitive data, but because information security is the other great field of interest for me)
2) done (still need to let the server-side validates some stuff that that for the moment I've done with javascript - i.e. cannot plan if it's past wednesday, cannot submit request if no checkboxes are checked, etc)
3) partially done: I've a working jsp which displays a dynamic table of the requests made by all users in the current week retrieving data from a servlet.
4) done

What I'm thinking of at the moment is the best/proper way to manage approvals/requests.
I attach here an image of the page displaying all users requests to the manager for his evaluation. Don't focus on the form layout as it's just a draft and a lot of stuff need to be adjusted.
How can I dispatch to different handlers based on the button? Assuming that having one servlet is the right approach...

I thought I could make something like:

But then how I could differentiate on the servlet side the processing?
I thought something like:

using a switch case statement for catching all different button names. But I'm not convinced at all with this approach.

Could you kindly give me some hints/suggestions on how to proceed?
I'm sorry if this sounds like a dumb question but as stated before I'm just starting to learn these technologies.

As a final note let me say I'll use this thread for any further question/issue I'll encounter as the project will move forward.

Thank you very much to everyone.

Marco
MultipleSubmit.PNG
[Thumbnail for MultipleSubmit.PNG]
 
Sheriff
Posts: 28331
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marco Canavese wrote:Assuming that having one servlet is the right approach...



So how would the design describe that servlet? "Accepts approval of a user request and accepts rejection of a user request" or something like that? But here we see the dreaded word "and" which tells us that the servlet has two different functions. A violation of the Single Responsibility Principle, I think.

However, I have written servlet code which handles more than one submit button and dispatches based on the name of the button. I may or may not have violated the SRP in doing so, I don't remember, but it's possible that I didn't. I'm sure there are legitimate uses for that idea.

As for your proposed code:



I would disagree with the idea of embedding the user ID into the button's name. If you just need to distinguish between "approve" and "reject" then call the buttons "approve" and "reject". If you need to distinguish between "approve Felicia" and "approve Samantha" then the user IDs should be put into hidden fields.

 
Marco Canavese
Ranch Hand
Posts: 34
2
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul for your quick reply and for pointing out the SRP which I didn't thought of.
The design of the servlet would describe it as "Accepts a user planning request or refuse a user planning request".

So if I understand it correctly it would be more appropriately from an ood point of view to have to different servlets, one for acceptance and one for refusals.

This principle states that if we have 2 reasons to change for a class, we have to split the functionality in two classes. Each class will handle only one responsibility and on future if we need to make one change we are going to make it in the class which handle it.


So if in the future I'll need to add a new action (for example put planning requests in standby or whatsoever) I'll create a new class, right?

Thanks for the tip of not embedding the user ID into the button's name, rather pass it as hidden value to the servlet.
My jsp has a <c:forEach> tag which loops the recordset retrieved from the servlet that dynamically creates the table in the picture I attached in my previous post.


My very newbie question is: if I add within the for each loop an hidden tag like this:

once I click on the row Accept or Reject buttons, I will get (on the servlet) the userId associated with that row where the button is clicked, right?
Dumb question, I know....

Thanks for your help.
Marco
 
Paul Clapham
Sheriff
Posts: 28331
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marco Canavese wrote:once I click on the row Accept or Reject buttons, I will get (on the servlet) the userId associated with that row where the button is clicked, right?



You will get all of the input elements in the form containing the button which was clicked. If you only want the input elements from one row, then make a form for each row. Or make the submit button into a link with suitable parameters; or I'm sure there are Javascript solutions which don't require form elements.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can i get the source code please for accept or reject.
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic