• Post Reply Bookmark Topic Watch Topic
  • New Topic

Autopopulating list of objects adding commas to String properties....why?  RSS feed

 
Ryan Kostrzewa
Ranch Hand
Posts: 31
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all - for background, I'm building a web application using Spring MVC.

On my web application, I have a dynamic form, where user can add Rows by clicking a button. Each row is represented in Java by an object, with a handful of properties. Nothing super complicated. As a user adds new Rows, each now Object is added to an Autopopulating List, and then stored in a database when the user hits Save.

The issue is, when I'm pulling the properties out of the Autopopulating List to store them, the list seems to have appended a comma. So, for example, if the user entered "Database Server" as the 'Role' property, when I print reqList2.get(i).getRole(), it comes out as "Database Server,". I find this odd, because the Row property isn't directly a part of anything that I think should be in any kind of csv format. It's not in a list with other rows. It's by itself, in an object, which is in a list of other objects. So I'm confused about where this comma is coming from, and how I can get rid of it.

This is obviously an abbreviated version of my code, but I've included most of what I think is relevant below. If there's any other component you think would be useful to see, let me know!

"AppendRequirements.jsp" -- this is fetched by Ajax and added into the webpage when the user clicks "Add New". The "Role" row, specifically is the one giving me this issue. It's also the only "Textbox" entry on this form, which may or may not be relevant to the problem.
Code:



recordModel.java


Requirements.java




daoImpl.java
 
Ryan Kostrzewa
Ranch Hand
Posts: 31
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CRISIS AVERTED!

So generally speaking, it looks like if you have two elements in your frontend code binded to the same path, that's when this issue occurs. I'd encountered it before when I was appending copies of the "AppendRequirements" section without incrementing the index. This time, it turns out I'd had what was supposed to be a separate property with each appended section to the same property. So, instead of the "Role" field mapping to the 'role' property and the "Quantity" field mapping to the 'quantity' property, I had both the "Quantity" and "Role" fields mapping to the 'role' property, due to a copy paste error.

So if you're having this issue, check and make sure you only have one field bound to each property in your front end code!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!