Win a copy of Kotlin for Android App Development this week in the Kotlin 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Controller dosn't act like expected  RSS feed

 
Master Rancher
Posts: 1107
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I working on a mvc app, for the moment specificly on the controller responsble for showing a list of privatemessages and to read them (pm's that is)
Let me first show the code and then explain what I'm trying to do.


So I have two getMethods mapped to privateMessages and readPm, both call the same method that fills the jsptemplate with the data. When I try to get the list of messages everything works fine, but when I click on a title to open the message, I get the empty template. I added two Sys.outs to see if the controller is being used and the if statements are executed, it is and they are. What is weird I'm using the same template for both urls, why is one being filled and the other one not...
Anyone an idea? The readPm also takes a list cause I wan't it to display the whole conversation
I someone askes themselfs why I use a StringBuilder and a string, it's bad pratice to concatenate a string in a loop or in a StringBuilder and otherwise I would have tons of appends.
@Stephan: before you make the remark... Yes I know I shouldn't inject html from the controller and should return the list to the jsp and itterate it there, but I doubt that's the issue...

Just to be exact I include the jsp to:
>
 
Saloon Keeper
Posts: 9710
192
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:@Stephan: before you make the remark... Yes I know I shouldn't inject html from the controller and should return the list to the jsp and itterate it there, but I doubt that's the issue...


You may be surprised, but it actually could be. Inserting HTML manually is extremely error-prone, and also makes your code hard to read and hard to debug.

I don't want to be blunt, but I doubt anyone will want to debug that code to give you the exact answer you're looking for.

I strongly recommend you move all HTML to the JSP, especially the hard-coded strings for which I really don't see ANY reason for them to be inside your controller. After you've refactored your code, you will probably be able to locate the source of your problems easily, or you can post the new code and people will likely be more willing to go through it.

At any rate, please post the generated HTML page for the two different actions.

I someone askes themselfs why I use a StringBuilder and a string, it's bad pratice to concatenate a string in a loop or in a StringBuilder and otherwise I would have tons of appends.


Well, the way you're doing it now makes the StringBuilder useless as well. Even though you perform an append for each message in the loop, most of the work is still going into allocating new strings over and over and over again for every concatenation that you perform inside the loop. You might as well not use the StringBuilder at all.

The point will become moot after you build a proper viewmodel though, because then you don't have to perform ANY concatenation, because the template engine will handle it for you.
 
Daniel Demesmaecker
Master Rancher
Posts: 1107
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So... I refactored my code a bit, moving all the html to the jsp and itterating the list there. I managed to find the issue. I was searching for pm's bassed on title and sender, while I was passing the recipient, so I was getting an empty resulset...
I do have a follow up question though, but since it's jstl related I start a new thread
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!