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

  • Home
  • SEARCH
  • 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 7937869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:38:18+00:00 2026-06-03T22:38:18+00:00

I have a example with h:datatable which is used to open a new page

  • 0

I have a example with h:datatable which is used to open a new page when the user clicks on a table row. Unfortunately this example uses the http header to pass argument to the opened page. My question is can this be implemented but with passing the argument into the background not with the header?

This is the complete source code:

This is the JSF page:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <head>
        <title>test</title>
        <script type="text/javascript">
            function addOnclickToDatatableRows() {
                //gets all the generated rows in the html table
                var trs = document.getElementById('myForm:dataTable').getElementsByTagName('tbody')[0]
                .getElementsByTagName('tr');
                //on every row, add onclick function (this is what you're looking for)
                for (var i = 0; trs.length > i; i++) {
                    trs[i].onclick = new Function("rowOnclick(this)");
                }
            }

            function rowOnclick(tr) {
                //                var childNodes = tr.childNodes;
                //                for(var i = 0; childNodes.length > i; i++) {
                //                    
                //                }

                var elements = tr.cells[0].childNodes;
                for(var i = 0; elements.length > i; i++) {
                    if ((typeof elements[i].id !== "undefined") &amp;&amp;
                    (elements[i].id.indexOf("lnkHidden") > -1)) {
                      //opne in a new window//  window.open(elements[i].href);
                        location.href=elements[i].href
                        break;
                    }
                }
                return false;
            }
        </script>
    </head>
    <body onload="addOnclickToDatatableRows();">
        <h:form id="myForm">
            <h1>Click on table row example</h1>
            <h:dataTable id="dataTable" var="data" value="#{datatableBean.lstData}" border="1">
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="ID" />
                    </f:facet>
                    <h:outputText value="#{data.id}" />
                    <h:outputLink id="lnkHidden" value="AnotherPage.xhtml"
                                  style="display:none">
                        <f:param name="id" value="#{data.id}" />
                    </h:outputLink>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Value1" />
                    </f:facet>
                    <h:outputText value="#{data.value}" />
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Value2" />
                    </f:facet>
                    <h:outputText value="#{data.value}" />
                </h:column>
            </h:dataTable>
        </h:form>
    </body>
</html>

This is the managed bean:

    package edu.home;

    import edu.home.model.Data;
    import java.util.ArrayList;
    import java.util.List;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ViewScoped;

    @ManagedBean
    @ViewScoped
    public class DatatableBean {

        private List<Data> lstData;
        /**
         * Creates a new instance of datatableBean
         */
        public DatatableBean() {
            lstData = new ArrayList<Data>();
            lstData.add(new Data(1, "Hello World"));
            lstData.add(new Data(2, "Hello 123"));
            lstData.add(new Data(3, "Hello abv"));
            lstData.add(new Data(4, "Hello qaz"));
        }

        /**
         * @return the lstData
         */
        public List<Data> getLstData() {
            return lstData;
        }

        /**
         * @param lstData the lstData to set
         */
        public void setLstData(List<Data> lstData) {
            this.lstData = lstData;
        }
    }

This is the class Data:

package edu.home.model;

public class Data {

    private int id;
    private String value;

    public Data(int id, String value) {
        this.id = id;
        this.value = value;
    }
    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the value
     */
    public String getValue() {
        return value;
    }

    /**
     * @param value the value to set
     */
    public void setValue(String value) {
        this.value = value;
    }
}

I’m sure that this is possible but I can thing of a way to pass the argument into the appropriate way.

Best wishes

EDIT
I understand that the h:outputLink must be changed this way:

<h:column>
    <f:facet name="header">
        <h:outputText value="ID" />
    </f:facet>
    <h:outputText value="#{data.id}" />
    <h:commandLink id="lnkHidden" value="AnotherPage.xhtml"
                    style="display:none">
        <f:param name="id" value="#{data.id}" />
    </h:commandLink>
</h:column> 

But I don’t understand how the managed bean must be changed. Maybe I suppose if AnotherPage.xhtml can access the managed bean of DataTable.xhml and take the value that I want to pass? But maybe then I need to change the javaScript?

  • 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-06-03T22:38:20+00:00Added an answer on June 3, 2026 at 10:38 pm

    You try using and render your table by yourself.

    Here is my sample. Modify it according to your requirement. I used JSF 2.0

    <h:form id="nextPage">
    
        <table>
            <ui:repeat var="row" value="#{shoppingCartMB.shoppingItems}">
                <tr onclick="clickedMe('#{row.productId}');">
                    <td>#{row.productId}</td>
                </tr>
            </ui:repeat>
        </table>
    
        <script>
    
            function clickedMe(id)
            {
    
                // Please modify following URL base on ur requirment.. 
                // Following is just for sample..
                location.href="#{request.contextPath}/product/" + id;
            }
    
        </script>
    </h:form>
    

    Here is some of pretty-config.xml

    <url-mapping id="productMB-loadProductDetail">
        <pattern value="/product/#{ productMB.productId }" />
        <view-id value="/pages/product-detail.jsf" />      
        <action>#{productMB.loadProductDetail}</action>  
    </url-mapping>
    

    There inside productMB (managed bean) ‘s loadProductDetail() , you put another redirect(..).

    Something like this..

    response.sendRedirect(request.getContextPath() + "/product-info");
    

    in pretty config again..

    You have to put config for above url..

    <url-mapping id="product-info">
        <pattern value="/product-info" />
        <view-id value="/pages/product-info.jsf" />
    </url-mapping>
    

    In my app, I did something like that to hide some URL.

    Hope this help.

    Here is my sample source code and my understanding.. I uploaded in zip file to 4shared.com
    http://www.4shared.com/zip/ctPZ4Dbj/URL_Hidding.html

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

Sidebar

Related Questions

This is tricky to explain. We have a DataTable that contains a user configurable
I have a table in a database which is used for storing application configuration
How to do following scenario: I have some DataTable which contains for example some
I have a DataTable which contains data in this format. I want to convert
I have a dynamic query which returns a DataTable. This DataTable will contain a
Does anyone have an example of using of populating a YUI DataTable with a
I have example: for line in IN.readlines(): line = line.rstrip('\n') mas = line.split('\t') row
I have a page which lists all the files in a particular folder (all
How can I get an array of datatable row numbers which meet a certain
I have a gridview which is bound to a DataTable. When I try to

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.