This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes How to implement tabs and workspaces within tabs. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to implement tabs and workspaces within tabs." Watch "How to implement tabs and workspaces within tabs." New topic
Author

How to implement tabs and workspaces within tabs.

Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
I want to create tabs within my Struts application where once a tab is selected, there will be navigation links down one side, and when links are selected, the remainder of the tab area will serve as the "workspace" for displaying the corresponding JSP page. I have tried using the struts-display tag library and have been able to generate tabs and panels for my links, but I'm not sure how to direct the jsp output to a specific panel in a tab.

Is there a better method to do this? I would like some possible suggestions on ways of accomplishing this that has ample documentation. I know this is a very common design these days, so I know there has to be a better way (or at least one with more documentation than struts-display library). Just looking for suggstions on technologies/frameworks that I could start investigating.

Thanks in advance,
Scott
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

I've always just used good old HTML, CSS, JavaScript and an iframe to hold the "workspace".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
Great suggestion. When I try using the iframe tag (pointing to test.jsp) I get the 404 resource not found error in Tomcat. Here's how I have it coded:

<IFRAME ID=adminlist src="/WEB-INF/jsp/mlist.jsp">
</IFRAME>

All my jsp files are kept in Tomcat under the /WEB-INF/jsp/ directory. Do I need to do anything differently? Usually I can just put the path from web app root directory to jsp directory and the app can find the files. Why is this different?

Scott
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Servlet containers do not allow web access to files under the WEB-INF directory.

In and MVC environment (such as with Struts), you typically forward to any JSPs. The browser is not requesting them directly.
To preserve your MVC archetecture, create a controller servlet that forwards to these JSPs using a requestDispatcher. Otherwise, move the JSPs out from under WEB-INF.
[ May 19, 2006: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
In my application, I have an action servlet that dispatches to one jsp, but now with iframes, that jsp page contains two iframe tags that both point to separate jsp pages. So, I'm dispatching to one jsp file that needs to refrence two other jsp files contained in iframe tags.

I hope I'm following your advice correctly. If not, please point me to some reference material on this type of thing. I'm just looking for a simple example (with code snippets).

Thanks for everyone's patience.
Scott
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Remember, in a page with frames, each frame generates a completely seperate request.

You could either

  • enhance your controller so that is knows how to dispatch to different JSPs according to the URL (preferred).
  • Create servlet entries and servlet-mappings for each of your frame JSPs.
  • Move the JSPs out from under the WEB-INF directory so that they can be accessed directly from a browser.

  • Scott Updike
    Ranch Hand

    Joined: Feb 16, 2006
    Posts: 92
    Are you saying that I would code the iframe SRC property in a way that the controller knows that this request is coming from this particular frame (and only this frame)?

    I think I need an example. Can you suggest a link/book/paper that has a simple example of how to do this?

    Again, many thanks.
    Scott
    Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410

    Here's one approach.

    Lets say you have one controller for the app.
    Set up one mapping that grabs any requests that end with ".do"



    Now, lets suppose you have 3 JSPs (a frameset, a menu, and a main page)
    Your framset (index.do) will have two frame tags:


    Now in your controller, write code that analyzes the URI and forwards to the proper JSP according to the URI




    When you hit the initial page, the servlet will forward to the index.jsp (your frameset page) page. Once the page loads in the browser, the browser will fire off two new requests, one for the menu and one for the main page.
    The controller will analyze each of these requests and forward to the correct JSP.
    Scott Updike
    Ranch Hand

    Joined: Feb 16, 2006
    Posts: 92
    Wow. Great response. I'll work with it and see where it goes.

    Thanks a lot for taking the time to provide an example. I'm also just starting the chapter on the command design pattern - what great timing.

    Scott
    Scott Updike
    Ranch Hand

    Joined: Feb 16, 2006
    Posts: 92
    Ok, I have one last question. When I try and add the frameset tags into my jsp (my tab actually) I don't see any output at all. I would at least expect to see empty frames or frames with the "Page not found" error, but I don't see the outlines of the frames at all. Here's my main display page:

    <%@ taglib uri="/tags/struts-html" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-layout.tld" prefix="layout" %>
    <head>
    <layout:skin/>
    </head>

    <html>
    <body>
    <layout:tabs styleClass="FORM" width="100%">
    <layout:tab key="Administration" width="50">
    <frameset cols="20,*">
    <frame src="display.do" />
    <frame name="workspace" />
    </frameset>
    </layout:tab>
    </layout:tabs>
    </body>
    <html>


    Where the controller forwards the display.do to a jsp page which lists my links. What's interesting is that when I was playing around with the iframe tag, I was getting it to display, but when I switched to the frame tags, I see nothing - just an empty tab. I really like the functionality of the frame tag as opposed to iframes.

    Do you know if there are any known issues with having frameset and frame tags within a display:tab tag?

    Thanks,
    Scott
    Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410

    I'm not a big user of Struts so I'm not sure what the tab tag does.
    You might want to ask that this thread be moved into the Struts forum.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to implement tabs and workspaces within tabs.
     
    Similar Threads
    Tabs in JSP(Struts 1.2 Based application)
    Tabs and sub-tabs problem
    display tag problem using with tabs
    retaining values
    jQuery tabs UI issue