• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tracking User's requests.

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically I have a Template. In the main JSP page, that inserts the template, then puts values into the areas of the template, I am going to use conditionals based on where the user is in my application. So I think I need a way to track what they are doing in essence. I can't see if a particular object exists because the main object will aways exist, and the actions that occur is adding to that object, and not really a source of knowing where the user is at.
I could create an Object that stores where the user is at into the Session. Then when they click on a link it will update the Object, and then go on. I feel weird about this solution, why I don't know.
Mark
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark. It's probably because it's 11:45pm and I'm in desparate need of caffeine, but I'm not really following you. Can you be a little more specific? What kind of information is being displayed? How does the view change to show different aspects/parts of the information? What do you mean by "where the user is at in the Session"? Is there some kind of flow the user is following?
When I see talk about using conditionals in the view, one question I like to ask is whether or not you are sure it should only be one JSP? It very well might be depending on your app, but sometimes you find that multiple views is what you really want. I once ran into Java's method size limit (620k? I can't remember.) because of a large JSP with lots of conditionals, so that has made me more aware of the issue.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK here it is. I have the main page. It is split into the Header, Footer, and a content section that is a Table with two columns. In the left column is a menu. The menu can be different depending on what screen they are in. The right side is the content, or Forms.
My application is about creating a Tour for a band. So you can enter Tour data like Band and name of Tour. Then in another screen you can enter Tour dates to the Tour. So one screen will have the tourdates listed. The user selects "Add Date" from the menu on the left, and the content now is a Form for entering a Date. Or the User selects "Change Assumptions" from the menu on the left, now the right side has the Assumptions form.
So my main.jsp could look like this.

Actually right now it looks exactly like that. So I need some object or something that I can use in the logic:equal tag to change the JSP files that are included in the main.jsp.
Does that make better sense?
Mark
[edited to disable smilies -JM]
[ April 17, 2004: Message edited by: Jason Menard ]
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just as a side note, the template taglib has been deprecated in Struts 1.1 in favor of tiles, so if you're using Struts 1.1, you might want to go that way. That beings said, looking at your jsp I personally would break it down into five separate jsps (if I counted correctly). They really are separate views, so there's no reason to force one template to do everything. It will also make it more clear when reading through your code and looking at your struts-config.xml which view your Action should be returning to if you have separate views. As i said, that's just my preference. I think it makes the design clearer and easier to follow. Introducing another object to track where the user is within your application would seem to unecessarily complicate things.
If you're absolutely determined to do it the way you presented, you could simply set a String in your actions with the given action performed to the request to be read by your <logic:equal> tags. For example, each Action might have a line in it like this:

Then just check "actionPerformed" with your <logic:Equals>. Of course you'd want to use constants instead of String literals in your code, but you get the point. Still, this isn't the way I would go. As I said, I would prefer to have separate jsps for each distinct view in this case. Your TourEntry action upon success might return to a jsp that's something like this for example:
tourEntry.jsp

Sorry if that's not exactly correct syntax, as I don't use the template taglib. HTH
[ April 17, 2004: Message edited by: Jason Menard ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jason. I am actually using Apress's book on Struts, first edition, and they do not have a section on Tiles in this edition. The new edition might have Tiles mentioned, if I recall when I looked at it at the bookstore.
It seems weird to me that having 5 seperate JSP pages, that basically look identical, would be a better solution. But I am very very new to any Web applications. I thought having that one Template and one jsp would make it a single source of truth. If I ever wanted to change my layout, I wouldn't have to change 5 JSP pages, I would change only 1.
I also thought that the struts-config.xml would be identical anyway since the individual JSP pages within the Template would be what is linked to the Action in the configuration.
Let me know what you think, because again I am asking for help because I am far from an expert in this area.
Mark
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the light of day, things seem a bit clearer for me. Aside from what we previously discussed, here's yet another alternative. You could set a request scope value in your actions for content and menu, and do away with the decision making in the jsp. It might look something like this:

I don't know if that's necessarily better or worse, but it is a different way of doing the same thing, and does simplify the template a little bit. But as I said, I've never used the template taglib and your way may be perfectly acceptable, and certainly does have some merit. Maybe somebody else can chime in with their two cents. In the grand scheme of life it won't really matter which way you go, but still it is an interesting design question. Now that I'm awake, I would probably tend to move away from what I suggested last night regarding the five templates (I was thinking five jsps in total, paying no attention to the fact that you have ten other jsps for the menus and content).
I also thought that the struts-config.xml would be identical anyway since the individual JSP pages within the Template would be what is linked to the Action in the configuration.
What does your struts-config.xml look like?
[ April 18, 2004: Message edited by: Jason Menard ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What does your struts-config.xml look like?


When I write it I will post it. I have to do that and creating the DynaActionForms and Actions for my application. I guess I kind of do things a bit backwards. I have already written all my VO and DAO objects, and I am also using ObjectRelationalBridge, which is already configured too. Oh, and my MySQL database is already set up.
Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, here is my new main.jsp.

I guess it does look much cleaner than the original.
Mark
[ April 18, 2004: Message edited by: Mark Spritzler ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at it, I think I need to match the Form and Action names for the classes to match. Like:
tourEntry
tourEntryAction
instead of
tourEntry
NewTourAction
OK, let me delete the above post, and repost it better.
Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK here is my second attempt at the struts-config.xml.

Mark
[ April 18, 2004: Message edited by: Mark Spritzler ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK third try, This time I put in all the DynaActionForms.

Mark
[ April 18, 2004: Message edited by: Mark Spritzler ]
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not see the tiles plugin in the struts-config.
Something like:
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitionConfigFiles" value="/WEB-INF/config/tiles-defs.xml"/>
</plug-in>

How's the attempt going? Receiving any errors?
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
marc,
this may be a nice resource for you:
http://www.lifl.fr/~dumoulin/tiles/
regards, and good luck
friso
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marc Peabody:
I do not see the tiles plugin in the struts-config.
Something like:
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitionConfigFiles" value="/WEB-INF/config/tiles-defs.xml"/>
</plug-in>

How's the attempt going? Receiving any errors?


I believe I have the tiles in the web.xml file. Is it supposed to be somewhere else?

Mark
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, sorry it took me awhile to get back to you. Looking at your struts-config.xml, one thing I notice is that all your <forward> elements inside your <action> elements are the same path, although you gave them different names. Why not just make a global "success" forward?

Next, the thing that bothers me is that I can't tell what your body and menu should be just by looking at the struts-config. Maybe it's a personal thing, but I like to be able to get an idea of the application flow just by looking at the struts-config. But, we can remedy that if you'd like by extending the ActionMapping class and adding attributes for "body" and "menu".

Now that we have this ActionMapping class, we can work it into our struts config.

Notice the className attribute which specifies the name of your custom ActionMapping, as well as the <set-property> elements used to set your body and menu properties.
Now that we have those, let's make use of them in our Actions. We need something like this in our Actions:

This could get tedious putting this in every Action, so let's make use of the Template-Method Pattern to extend Action and save us some typing. First we need a base action that will contain our template method.

Naturally you'll probably want to make those String literals constants, but you get the idea. Now that we have our base action, this is how we would do our specific Action classes:

How's that work out for you? You gain the reusability of your single template, plus you move your templates body and menu jsps into the struts config. Using the template method pattern, your custom base action will run the logic in your subclassed actions' run() method, extract your menu and body jsps from your custom ActionMapping and set them to the request for your tiles template.
What do you think?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that sounds cool. You know I always like simple and easy. And less code writing. There is just so much refactoring when it comes to web applications.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so now I am lost and confused. Sorry.
I have the Action class, and extended it and now we have the struts-config changed. So there is a TemplateActionMapping class and a TourMilesAction class that will be the base classes that the actual Action classes will use.
I have the Value Object and Data Access Objects all complete. I have my configuration files complete. I know I still need to write the actual HTML forms for the view. But now I can't seem to figure out if I have Business Delgates, need them or not, and if I still have to write them.
It would seem that I would have finished this application faster doing it the HTML to Servlet to (EJB or Plain Old Java class route.
Mark
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But now I can't seem to figure out if I have Business Delgates, need them or not, and if I still have to write them.
Here's the general flow: Struts Action calls method on Business Object, BO uses DAO and returns VO to Action. Action moves VO data to form if necessary or puts the VO in some scope (request, session, application) for use by the view. View uses form data or VO to display data back to user. Lather, rinse, repeat.
It would seem that I would have finished this application faster doing it the HTML to Servlet to (EJB or Plain Old Java class route.
Once you get used to it, it should almost always be faster using a framework such as Struts.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jason. I now know that I do not have my Business Delegates written at all.
I never repeat when I wash my hair.
Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jason, for some reason the pages aren't showing the content jsp pages. It is getting the correct menus on the left, but the right side that is supposed to have the body is not getting filled in. I try to view source through IE, and it doesn't come back with anything so I can't tell if anything is getting into the body or not.
Thanks
Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I know that it is getting the body value from the strut-config. I had it output that value to the console and it displayed the correct body filename.
Here is the layout.jsp middle portion for the menu and the body.

As you can see I have the menu and body looking almost identical. One works, the other doesn't.
Hmmm..
Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mark Spritzler:
OK, here is my new main.jsp.

I guess it does look much cleaner than the original.
Mark
[ April 18, 2004: Message edited by: Mark Spritzler ]


I found it. The main.jsp file has request.getAttribute("content") which
should have been
request.getAttribute("body")
Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic