Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 992585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:17:30+00:00 2026-05-16T06:17:30+00:00

I am looking for a way to inject values from the fragment (#) of

  • 0

I am looking for a way to inject values from the fragment (#) of a URL into bean(JSF), in the same way query-parameter values are injected. I am using Ben Alman’s Bookmarkable jQuery plugin (http://benalman.com/projects/jquery-bbq-plugin/) to create the URL fragments. I was hoping that Custom regex patterns from prettyFaces could be a way to solve my problem but until now I have been unsuccessful.

(http://ocpsoft.com/docs/prettyfaces/snapshot/en-US/html_single/#config.pathparams.regext)

I would like to define here my situation and if any one has an idea, i
would love to try them out.

I am using
RichFaces: 3.3.3,
Spring: 3.0.2.RELEASE,
Hibernate: 3.5.3-Final,
JSF: 2.0.2-FCS,
PrettyFaces: 3.0.1

The web application generates, following kind of URL where parameters
are listed after a hash(#). The idea is to have an ajax based
Bookmarkable URL. So every time I click on an element that changes the
state of the system, the value is sent to the server via ajax and the
URL after the hash is rewritten. There can be 1 to 3 parameters after
the hash, the number of parameters are optional.

My goal is, when the user bookmarks the URL (with hash) and than
revisits the saved page, the page should inject the correct values
into the system and visualize the page in the previous state (like
query-parameter).

Below, I have a regular expression that would catch all the parameters
after the hash.

//URL:   
http://localhost:8080/nymphaea/workspace/#node=b48dd073-145c-4eb6-9ae0-e1d8ba90303c&lod=75e63fcd-f94a-49f5-b0a7-69f34d4e63d7&ln=en

//Regular Expression:    
\#(\w*\=(\w{8}-\w{4}-\w{4}-\w{4}-\w{12}))|\&(\w*\=(\w{8}-\w{4}-\w{4}-\w{4}-\w{12}))|\&(\w*\=\w{2})

I know there are websites that some how send the URL fragment into there server side logic,

  • http://maps.yahoo.com/#mvt=m&lat=36.952736&lon=-95.84758&zoom=11&tt=starbucks&tp=1&ioride=us
  • http://www.cbc.ca/video/#/Shows/Death_Comes_to_Town/ID=1365210427

Is there anyway to inject values from the URL fragments into server side beans?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:17:30+00:00Added an answer on May 16, 2026 at 6:17 am

    You can do this with help of window.onhashchange which fills an input field of a hidden form which submits itself asynchronously when the input field has changed.

    Here’s a kickoff example of the Facelets page:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" 
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html">
        <h:head>
            <title>SO question 3475076</title>
            <script>
                window.onload = window.onhashchange = function() {
                    var fragment = document.getElementById("processFragment:fragment");
                    fragment.value = window.location.hash;
                    fragment.onchange();
                }
            </script>
            <style>.hide { display: none; }</style>
        </h:head>
        <h:body>
            <h:form id="processFragment" class="hide">
                <h:inputText id="fragment" value="#{bean.fragment}">
                    <f:ajax event="change" execute="@form" listener="#{bean.processFragment}" render=":showFragment" />
                </h:inputText>
            </h:form>
            <p>Change the fragment in the URL. Either manually or by those links:
                <a href="#foo">foo</a>, <a href="#bar">bar</a>, <a href="#baz">baz</a>
            </p>
            <p>Fragment is currently: <h:outputText id="showFragment" value="#{bean.fragment}" /></p>
        </h:body>
    </html>
    

    Here’s how the appropriate bean look like:

    package com.stackoverflow.q3475076;
    
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.RequestScoped;
    import javax.faces.event.AjaxBehaviorEvent;
    
    @ManagedBean
    @RequestScoped
    public class Bean {
    
        private String fragment;
    
        public void processFragment(AjaxBehaviorEvent event) {
            // Do your thing here. This example is just printing to stdout.
            System.out.println("Process fragment: " + fragment);
        }
    
        public String getFragment() {
            return fragment;
        }
    
        public void setFragment(String fragment) {
            this.fragment = fragment;
        }
    
    }
    

    That’s all.

    Note that the onhashchange event is relatively new and not supported by the older browsers. In absence of the browser support (undefinied and so on), you’d like to check window.location.hash at intervals using setInterval() instead. The above code example should at least give a good kickoff. It works at at least FF3.6 and IE8.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.