0

I have a Spring-based java project. At frontend I have jQuery. The main jQuery compoinent is Tabs, so access to my main page can be http://myIp/project/myController#Tab1

I need to ways to go to this page:

  • via redirect: redirect:/myController#Tab1 (and this case works)

  • [when validation fails] I need to pass them back via return "adminOperations#Tab1" (and this case doesn't work)

Definition of 'adminOperations':

<definition name="adminOperations" extends=".mainTemplate" >
    <put-attribute name="title" value="Admin page" type="string" />
    <put-attribute name="content" value="/jsp/admin.jsp" />
    <put-list-attribute name="scripts" inherit="true">
        <add-attribute value="admin.js" type="string" />
    </put-list-attribute>
</definition>

Template Page content:

<html>
<head>
    <title><tiles:getAsString name="title" /></title>

    <tiles:useAttribute id="scripts" name="scripts" classname="java.util.List" />
    <!-- processing script & styles data -->
</head>
<body>
<div id="header">
    <div id="headerTitle"><tiles:insertAttribute name="header" /></div>
</div>
<div id="content">
    <tiles:insertAttribute name="content" />
</div>
<div id="footer">
    <tiles:insertAttribute name="footer" />
</div>
</body>
</html>

How to implement correct processing of '#' symbol in this tiles?

davs
  • 9,226
  • 8
  • 41
  • 54
  • ue question is bit unclear..you should post ur controller file as well as admin.jsp . via redirect: redirect:/myController#Tab1 (and this case works) [when validation fails] I need to pass them back via return "adminOperations#Tab1" (and this case doesn't work){which validation?} .Post the admin.js file as well.. – Rajesh Jul 12 '12 at 09:19

1 Answers1

1

The hash is purely a browser thing. When you send a request to a URL like /foo.action#bar, the browser sends a request to /foo.action, renders the HTML from the response, then finds an anchor with the bar name or ID in the HTML, and scrolls to this anchor. If you send a request to /foo.action (when submitting your form), there is no way for the server to change the URL the browser sent a request to and to tell it to go to the bar anchor.

The only way is to generate an HTML page containing a JavaScript function called when the page is loaded and jumping to the bar anchor. See How to scroll HTML page to given anchor using jQuery or Javascript? for how to do that.

Community
  • 1
  • 1
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255