0

I have a header,menu and a body to load the jsps. When i click a menu element everytime, the entire tile reloads. But i want to show the users the selected menu item. Since the tiles reloads, i am not able to get the element which was clicked by the user.Please let me resolve this. Thanks

  <definition name="main-tiles" template="/WEB-INF/jsp/menu/home.jsp">
    <put-attribute name="header" value="/WEB-INF/jsp/menu/header.jsp" />
    <put-attribute name="menu" value="/WEB-INF/jsp/menu/menu.jsp" />
    <put-attribute name="body" value="" />    
  </definition>

  <definition name="home" extends="main-tiles">
    <put-attribute name="body" value="" />
  </definition>


  <!--  User Tiles -->  
  <definition name="newUser" extends="main-tiles">
    <put-attribute name="body" value="/WEB-INF/jsp/userandorg/user/newUser.jsp" />
  </definition>
SDC
  • 161
  • 1
  • 11

1 Answers1

2

Tiles don't really 'communicate' with each other.

When a tiles-composed page is fully rendered in your browser, view the html (view source) and you should be hard-pressed to see any tile framework showing through. This means that when your user clicks on a menu, it is a round-trip communication back to your server which runs through your servlet code and then uses the tiles framework to compose the resulting html.

What you describe as the desired behavior is more like frameset or iframe behavior where different sections of your browser pane are literally different requests/responses. You can achieve the same effect with AJAX frameworks which can be a call to your servlet and then dynamically update specific blocks of your html (usually defined as div or span elements) without refreshing the entire page.

But, if you want to merely highlight the clicked menu using your tiles composition, have your servlet identify which menu was clicked and then use some JSTL on your menu.jsp page to identify the menu item link and provide some CSS styling to the menu link. It is still a round-trip (non-AJAX) communication, but it should give you the effect you describe.

majorbanzai
  • 551
  • 5
  • 11
  • Hi.Thanks for your suggestion. But is it possible for my jsp to communicate with menu.jsp to highlight the selected value?Since both the jsps are rendered inside home.jsp – SDC Jan 10 '13 at 08:12
  • 1
    No. home.jsp is your template, but menu.jsp is physically a separate jsp. When the user clicks a menu link and the request is sent to your servlet, the servlet should know which menu was clicked, like the difference between _Show Foo_ and _Show Bar_, right? The servlet would know because of the specific `URL` or perhaps by a `query parameter` on the request. When the servlet is done doing its action, it can place an `attribute` in the request for your menu.jsp to find, or menu.jsp can use an existing `parameter`, and then use an `if` statement to style the clicked link something special. – majorbanzai Jan 10 '13 at 08:34