*
The moose likes JSF and the fly likes Simple pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Simple pattern" Watch "Simple pattern" New topic
Author

Simple pattern

Kevin Galligan
Ranch Hand

Joined: Aug 10, 2005
Posts: 70
I've been playing around with JSF for a few weeks now. I'm still a little shakey with the contrast between the routing in a JSF app and the routing in every other app I've ever worked on. Take for example the links on this forum page...

***New Topic***
http://www.javaranch.com

ubb (command) = newtopic
f (forum id) = 82

***Existing Topic***
http://www.coderanch.com/t/210870/JSF/java/Tough-choice-Struts-or-JSF

ubb (command) = get_topic
f (forum id) = 82
t (topic id) = 000417

Why there are 3 zeros before the top id number is beyond me, but I understand the general pattern. The disconnect I have with navigation on a JSF site is that that pattern would be different.

An example. Most of my development basically involves walking around a database. Entry screens generally focus around a course entity that point to one or a small handful of tables.

In "classic" development, the code would print a list of entries in a table with links based on id to a detail page...

/admin/ThingDetail.do?thingId=123

Something like that. Then, I'd have the struts form include that as a value.

In the JSF books I've been reading and working with, the general pattern appears to be using the dataTable tag and DataModel class to wrap a collection of some type. In the limited time I've been working with this, it feel clunky. The method of just putting out links with id's seemed more natural for the way the browser is built.

I just saw the post for struts vs jsf...

http://www.coderanch.com/t/210870/JSF/java/Tough-choice-Struts-or-JSF

So I thought this would be fresh on peoples minds. I have an app that I'm currently working on that I was considering adding some jsf to, at least for form screens. The navigation (to some degree) and current forms are handled by struts. I also have a new application that I'm starting, and need to figure out which way to go. I also run a technology group at my day job, and I'd like to figure out if we should make some kind of change (and some of the folk don't really like struts, which I think is hogwash, but what do I know? I'm more hacky than they are).

In general, I'm thinking of doing a hybrid myself. Navigation around the system with "classic" get urls, and forms wizards with jsf. Anybody else doing this? Any advice, usage patterns?

Here's my attempt at a diagram (I don't know how this will come out in the forum)



Thanks in advance.
Kevin Galligan
Ranch Hand

Joined: Aug 10, 2005
Posts: 70
PS. Any thoughts on ide? I was thinking of renewing my personal license to IDEA, but I'm not sure if its worth it. Anybody do JSF in IDEA? There's no visual editing, but I'm not sure its worth it. I've been evaling exadel, myeclipse, and Nitro. We I to pick up any, I'd lean towards exadel, but again, not sure if its worth it. Its mostly a mix of the jsf stuff, and the hibernate utility.

I'm quite used to hand editing of pages, but from what I can gather, JSF was really designed for RAD visual editing.
Daniel Prene
Ranch Hand

Joined: Jul 15, 2005
Posts: 241
I use myeclipse... I'm not all to happy with it, but it seems that newer updates are bringing more and more support. What are you using now?
Kevin Galligan
Ranch Hand

Joined: Aug 10, 2005
Posts: 70
For jsf editing I didn't like myeclipse much at all. I liked the hibernate tool, but you can't really update your mappings once you've created them.

I'm evaluating exadel and Nitro. My Nitro at home ran out of 15 days and I didn't really get much time to play with it. I have one at work that will probably run out soon too. I'm supposed to have a web demo in a couple weeks. We'll see. They'd really have to blow me away at this point, though.

Exadel seems to be pretty good for jsf editing, and the hibernate stuff is ok too. I'm still having flakey things with either eclipse or exadel, though.

Right now I tend to code with some exadel as front end, and do all of my java in IDEA version 3. I own a copy of 4.5 but I think they hit a level of perfection with version 3 that's been hard for anybody to beat. However, I'm going to force feed myself version 5 now.

I was hoping exadel and eclipse could be my new 1 platform, but I just can't shake IDEA. I'm sure you can do all the same stuff, but its just not as convenient. At least not to me, as I'm used to idea.

eclipse picks up file changes from the disk, though, and vice-versa, so no big deal (other than the fact that they're both memory hogs. Toss weblogic or jboss on top of that, and it gets up there).
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

To explain the URL:
http://www.coderanch.com/t/210870/JSF/java/Tough-choice-Struts-or-JSF

These are GET parameters. Also knows as Query Strings. In a typical J2EE application you retrieve these via the doGet() method of your servlet. So if you did:

request.getParameter("ubb")

it would return get_topic. f in this case is the forum id. t is the thread id. The reason for the preceeding zeros on the thread id is probably due to the fact that UBB is perl based and uses flat files instead of a database. By prefixing with zeros you keep the threads indexed in order on the filesystem.

Now, on to JSF. Although knowing how J2EE works from a Servlet standpoint is crucial to any framework, you kind of have to put by the way side when developing JSF applications. You have to change your way of thinking from request/response to components and actions. Once you can force yourself to stop saying "but with a Servlet I'd just do this" things will go smoother. JSF is very MVC. While you can develop MVC using Servlets and JSP's they aren't forcing it. JSF is.

As far as IDE's go...I use IDEA. I hand code everything. It's interesting to see that most hard core java developers do. And they can get done just as fast as those that use IDE's to generate code for them. And it's cleaner too. Now I do use IDEA's templates and nifty editing features like automatic getter/setter creation, auto method inclusion on interface implementations, etc. But that is me. You need to try a few IDE's out and see what best fits your development style. While we can suggest till the sun goes down what to use, you'll never know until you give it a go.

I hope this helped and didn't just complicate things even more.


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

One last comment..

In general, I'm thinking of doing a hybrid myself. Navigation around the system with "classic" get urls, and forms wizards with jsf.

There is a JSF-Struts project (link edited in when I find it) that does this. So don't try and roll your own. It will only lead to more confusion. Personally, I think JSF's navigation handleling is fine the way it is. I'm not sure whey other people think Struts' is better. Probably because they are used to Struts. JSF's is actually simpler. Less files and less XML.

If you are comfortable enough with JSF, I'd say use it for new projects. For existing projects I'd say if it ain't broke, don't fix it.
Kevin Galligan
Ranch Hand

Joined: Aug 10, 2005
Posts: 70
You haven't confused anything. I guess what I'm saying is I'm not sure that the jsf navigation really is that great. The system acts flakey if you use the back button or refresh ever. I know these are no-no's in the jsf world, but I can't really see myself telling clients that, you know? I think I could argue that easier on maybe a wizard or whatever.

As for the links...

Struts-Faces:
http://struts.apache.org/faces/index.html

Shale:
http://struts.apache.org/shale/index.html

This dilemma of mine kind of goes back to my original ranch post...

http://www.coderanch.com/t/210839/JSF/java/Simple-list-table

Your solution does work, but it still seems significantly more complicated than it needs to be. Like there's more going on than needs to be going on.

The custom datatable from myfaces is not standard, so anybody building a simple table maintenance app using the standard datatable would still run into the problems I was running into. What's worse, is if they're fairly junior and just slapping an app together visually. RAD isn't always good.

Even with the custom tag (said in my post that I was going to crack open the code and look at it, which i didn't), I assume on submit it must get the list again (which is pulling from the db again), and scan through them to look for the submitted id. While at least its consistent, its certainly not efficient.

I'm going to work with it some more and maybe I'll see the light, but I'm still not getting the big flash of clarity. At least with the navigation. The other parts I like.

As for IDEs, I have a feeling I'll stay with IDEA. I think the less open development nature has kept it simpler yet powerful. I think version 3 was one of the best IDEs ever, but version 4 was a little bloated. However, as I said in a post above, I'm going to start force feeding myself version 5 and move on with life.

Thanks again.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Well, the whole back button is a known issue that is supposed to have been fixed in 1.2. So we'll forget that for now. Here is the deal..I am not trying to pursuade you to use JSF or any other framework for that matter. I think that people that get so emotional over something like JSF or Struts are losing sight of what's important. And what is that you ask? Getting the job done. Period. If you think JSF is not for you, the solution is simple, don't use it. There are plenty of options, eg Struts, Tapestry, Wicket, WebWork, Spring. It's daunting really, and a bit overwhelming for a newbie. And every single one of those frameworks has it's advantages and disadvantages. As a developer our job is to figure out what makes us most effeciant.

Personally, I find the model driven aspect of JSF very comfortable. I also like Pizza, Football, and Dogs. Maybe you like Salads, Golf, and Cats. If you did, I'd make fun of you, but it's your choices.
Kevin Galligan
Ranch Hand

Joined: Aug 10, 2005
Posts: 70
The back button I did some research into. I don't know if its going to be fixed in the sense that the navigation would work like a "classic" app's back button would work as much as it'll prevent a user from submitting a form that they've "backed" to.

Its not that I want you to convince me of using one thing or another, or a religious discussion. I'm just trying to get a better understanding of the systems, how people are really using them, etc.

I like JSF, but for the navigation piece. By "navigation piece" I only mean the book-learned method of walking a database by way of dataTable tags. The rest of it is ok by me. In fact, I'm not sure I see the value of a struts integration piece for a new app. I looked at struts-faces (briefly), and I'm not even really clear on what it does.

So, back to my original question. I mean, I understand the model is just different, but the pattern I've put out there is pretty common and I think could use a better solution. Let me set up a more clear example:

page: /someapp/FooList.jsp

displays: A list of foos found in the database. Each foo links to a foo edit page (/someapp/FooEdit.jsp). It sends a param 'fooId' to the request on the query string.

page: /someapp/FooEdit.jsp

displays: A particular foo. Takes a 'fooId' argument passed (or bombs if none passed). The user can edit properties of foo.

Now, to model this with "classic" jsp, we could create a java bean for FooList, which has a method that returns a list of foos. This method would simply connect to the database and create this list from current data. The jsp page would display each foo along with a link to...

/someapp/FooEdit.jsp?fooId=xxx

******JSF version******

The jsf version (again, what I got from at least the O'reilly book) would work as follows:

page: /someapp/FooList.jsf (still a jsp page, but mapped)

displays: A dataTable tag backed by a DataModel with a list of foos. Clicking on a commandLink will cause an action method to put a particular foo into the user's session and pass them to the edit page

page: /someapp/FooEdit.jsf
displays: The edit page. Shows the foo in the session (put there by the list page).

The problem I've had here all along is that, using the standard dataTable:

1) If you keep the list or DataModel in the session and not pull it from the database, your data will be consistent when you click on the link in FooList, but in order to see an update of current data in the database, you need to have an explicit link somewhere on the page to tell your code to dump the current data and reload. This is IMHO unnatural for a webapp, and keeps a lot of data sitting around in the session.

2) If you grab the list every time from the database, this will keep the data in the page current but has a couple problems. When you click the link, you need to regrab the whole list to get your particular Foo. That's just a performance problem. The big problem is that if the data has been updated since you saw it, you could be grabbing the wrong record. Like you click on foo with id 7 but you actually get foo id 8.

Now, we've had this discussion as mentioned before. The solution was the myfaces custom table. That does solve the data update problem in #2 above, so your data will be consistent. However, it doesn't do anything about the performance issue. You still need to grab the whole data set. Its actually slightly worse because you also have to scan the data and look for your id. Right? Not the end of the world, but if you had a lot of users hitting a site, I wouldn't recommend it. That, and not everybody is using myfaces or knows to use that custom tag.

Now, why did I go through all that? I don't want anybody to convince me to use or not use JSF. I'm just pointing out what I think is a place for improvement, or at least for a different way of implementing it. Either that, or somebody to say, "no, your assumptions are wrong here. Its not doing x. Its doing y.". Either that or, "well, there's a performance issue, but the development efficiency inherent in x might be worth it. Its a tradeoff". At the very least I think discussion is good. At best it might turn into some type of new component specific to the problem.

I like Dogs and pizza. Cats are not my bag. Girls with a single cat are ok, but multiple is a red flag.

I played football, but get bored watching sports.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Kevin,

I am short on time this evening, but I will for sure make a response sometime this weekend when I have more time. I am enjoying this discussion.

Now, why did I go through all that? I don't want anybody to convince me to use or not use JSF. I'm just pointing out what I think is a place for improvement, or at least for a different way of implementing it. Either that, or somebody to say, "no, your assumptions are wrong here. Its not doing x. Its doing y.". Either that or, "well, there's a performance issue, but the development efficiency inherent in x might be worth it. Its a tradeoff". At the very least I think discussion is good. At best it might turn into some type of new component specific to the problem.

Agree 100%. Let's get to the bottom of it. I'll post more later. Tonight I'll be watching the Busch race at Bristol.
Kevin Galligan
Ranch Hand

Joined: Aug 10, 2005
Posts: 70
Sweet. My roommate is into Nascar, so that may be on at my place tonight. I'm currently doing a release, then heading home for a quiet night of playing on the computer. I will be messing around with this tonight. Very, very lame. I know.

I was in Vegas for the first time last weekend. Probably the last time.
Kevin Galligan
Ranch Hand

Joined: Aug 10, 2005
Posts: 70
I had a thought this morning on the way into work. If the extended datatable from apache can use the id value as its index rather than the actual position index, it probably passes that in as the argument, yes? Then maybe we could declare another method binding on that table tag. If that method existed, instead of getting the list and scanning for the selected value, it would simply call that method to set the selected id value, and then call the action method. It would leave the DataModel alone and not flag the selected value. It would be up to the person implementing the app to use the passed id value to get the object.

More work? A little ugly? Yeah, but better performance. I'm just thinking that higher volume situations would be better with something like this.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I didn't get a chance to look into this over the weekend. Doing that now. There are some similar discussions on the MyFaces mailing list that I am scanning over first...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Simple pattern
 
Similar Threads
Journal Article - JavaServer Faces 1.0 Part I
Struts vs JSF
[JSF] Duplicate component id
Advantages of JSF over Struts
Tough choice Struts or JSF