Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets 4a blocked

 
Jeremy Medford
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a heck of a time making progress on Servlets 4a. I thought I was doing quite well, but have hit a serious block where I can't get attributes from within listvideo.jsp once I've tried to add a new video. So that is my biggest hurdle, but I'd like to start by getting comments on my approach.
Is this the preferred method of handling multiple actions when using ActionServlet? (Sorry if I am sharing too much code. If so, is there a better way for getting input at this early stage?)



Should I move the last else into the first block and use some logic to determine whether we have just added a video or arrived for the first time from index?
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy, think about the difference between an action, which is the result of clicking a button in the form, and the information passed along as parameters when someone completes the form, then clicks the submit button. The key to handling actions lies there.
 
Jeremy Medford
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all, I feel like I'm starting to make some progress here. I now have the following code structure in VideoServlet and I have a question:
(Hopefully this isn't too much code being displayed.)


1. When I begin fresh at my index.html and select 'List Videos', I am taken to the Video List but I have one row that shouldn't be there. It is filled with nulls for the strings and a couple of default "no's" for the booleans. It's as if it the AddSubmitHandler() is being used instead of my Default(). Why might this be happening? I thought Default would be used if the action does not match the others inside init()?
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy Medford wrote:Thank you all, I feel like I'm starting to make some progress here. I now have the following code structure in VideoServlet and I have a question:
(Hopefully this isn't too much code being displayed.)


1. When I begin fresh at my index.html and select 'List Videos', I am taken to the Video List but I have one row that shouldn't be there. It is filled with nulls for the strings and a couple of default "no's" for the booleans. It's as if it the AddSubmitHandler() is being used instead of my Default(). Why might this be happening? I thought Default would be used if the action does not match the others inside init()?



Ooooh, ooooh! I think I remember this same thing happening to me! Here's a hint: In init() Order counts!
 
Jeremy Medford
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, yes order does seem to matter. However, as I play around with the order within init(), I still am seeing undesirable behavior depending on any order I place the addActionHandler statements.

1) Why does order matter?
2) Why does an incoming request with supposedly no action essentially get handled by whatever is first in the list of statements in init()? Do I need to change the action from "default" to ""? I will try this and see.

- Jeremy
 
Jeremy Medford
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that does not work. If I reorder the statements like this:



, I get a happy (empty) initial Video List. Then, I attempt to add a video and am directed to the add video form. Great! Then, when I 'submit' the new video, I am brought to an empty video list. This is weird because I have an action = "addnewvideo" and it still executes the 'Default' handler. I fear I am missing something fundamental here. Another hint PLEASE?!?
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I remember my struggles with this assignment, the values for your individual action buttons in all of your forms must match the string for that action in your actionHandlers exactly, or default will be the one used. I noticed at least one of the string values you used for your actionHandlers is different than the ones I have. I'd look at that first.
 
Jeremy Medford
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help!

They seem correct.

From index.html:

From addvideo.jsp:

From listvideo.jsp. This one behaves correctly every time:

And, once again my init():


Could there be some stale files hanging around in the deployment location?


 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those aren't the actions to which I am referring. Maybe my terminology is wrong, but I'm referring to the actual action of clicking a particular input button on your form. The buttons are labeled with text so you know which action you are performing when you click on it, and that text must match the String in your corresponding actionHandler so your code knows which action you performed. If it doesn't match, the first one listed is the default! (Which should be default, as we have discovered!) Look at the value you have assigned to your input buttons, and match that text to the appropriate addActionHandler String and see if it doesn't work. Keep me posted!

 
Jeremy Medford
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carol,

Yes! After I matched the 'name' of my submit button to the appropriate addActionHandler, I started seeing the Video added to the list! And, my initial link to the list from index.html does not display any empty Video table rows! It's a thing of beauty.

I appreciate the gentle nudges. Now I can move on.

Jeremy
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic