• Post Reply Bookmark Topic Watch Topic
  • New Topic

This is why I don't like JSF  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically what I have is I need to be able to add keywords to a select list from a textfield. Then, upon save/update, I need to be able to get all the items from the select list.

To get all the items, here is what I did:



This works fine. The problem then became in how I was adding items to the select list. Originally, I was using javascript to add items and I used a commandButton with a type="button" and use the onclick to call the javascript function. However, what I realized is that since the model for the select list isn't being updated, I don't get the new values I added using the above solution.

So what I had to do was add keywords to the select list using Java code. I did it like so.



While this works, it seems silly to me that I need to hit the server to do this. Actually, pretty rediculous. Sure, I could incorporate some Ajax to update the model so I wasn't having to send so much across the pipe, but even that seems silly. Maybe I am just doing it wrong. Geez, I'd hope so.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, allowing for the fact that I rarely read code samples correctly online (I have to print them out), I'd say that you want to have your cake and eat it too. That is, you're manipulating data on the client for the benefit of an app that's on the server.

That's fine as long as when it's important, the server's data model is brought back into sync with the client.

Obviously the most reliable, but slowest method is to round-trip the server every time you update the GUI. Bleah.

Next fastest would be an AJAX approach where essentially the same thing happens, but behind the scenes. Which I think was what you're indicating. More work, not much better.

Fastest of all is to accumulate the changes and send them to the server in a chunk. BUT you have to make sure that there's no way that people can bypass the update operation, or you'll lose the changes.

So here's what's right with JSF:

JSF is a component-based design. That means that if someone is kind enough to develop a component that generates both the JSF code and appropriate support JavaScript, you can just drop it in and not have to worry about it.

More important, a well-designed component will sense if the user has turned off JavaScript and fall back to the brute-force approach.

The catch is, you need someone to write such a component. Or write it yourself. Hmmm. I $ens$e an opportunity here! :p
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously, I am taking this out of context with regards to JSF features, however...





See how simple that is. And no matter what I do with the options in javascript, the server gets them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!