How to click on h:datatable and open a new page

Hi,
I'm new to JSF. I have a basic example with JSF h:datatable which displays data. When I click on the table row new page is opened and an argument s passed via the http header:
Datatable:
<?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.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>
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;
The Java object: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;
The page which is opened after the row is clicked:<?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">
<head>
<title>TODO supply a title</title>
</head>
<body>
<h1>This is another page</h1>
<h:panelGrid columns="2">
<h:outputText value="Selected ID" />
<h:outputText value="#{anotherPageBean.id}" />
</h:panelGrid>
</body>
</html>
The managed bean of the opened page:package edu.home;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
@ManagedBean
@RequestScoped
public class AnotherPageBean {
private int id;
* Creates a new instance of AnotherPageBean
public AnotherPageBean() {
try {
this.id = Integer.parseInt((String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id"));
catch (Exception e) {
this.id = 0;
* @return the id
public int getId() {
return id;
* @param id the id to set
public void setId(int id) {
this.id = id;
My question is how I can pass the argument into the background, without using the http header? Can you help me to implement this example?
Best Wishes
Peter
Edited by: 932633 on May 7, 2012 3:18 PM
Edited by: 932633 on May 7, 2012 3:18 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

EJP wrote:
And why all the futzing around in Javascript? Why not just use &lt;a&gt; or <h:outputLink> in the normal way? What value are you trying to add here?
I'm new to JSF.OP answered that already. I guess the OP really wants to turn a table row into something clickable, a link won't suffice then. Basic JSF tags don't support tagging event handlers to individual rows/columns as far as I know.
@OP: you should really check out extension frameworks like Primefaces which have more advanced datatable implementations. Check out this for example:
http://www.primefaces.org/showcase/ui/datatableRowSelectionInstant.jsf
There is also Richfaces, Icefaces, Tomahawk. Probably using any of these extension frameworks you hardly ever have to write manual javascript.

Similar Messages

  • Does anyone know if there is a way to arrange songs on a playlist that has 100 songs? I used to be alble to double click and open a new page but that is no longer an option. Because you cant get a total view of the playlist it is almost impossible

    I used to be alble to double click and open a new page but that is no longer an option. Because you cant get a total view of the playlist it is almost impossible.. if a song is in position 95 and I want to put it at 3 I have to hold it and drag it till the curor moves.. This makes creating an order almnost impossible because you cn only see half of the songs

    1.SmartyPanouZe3rd,
    Sep 4, 2013 1:03 PM   in reply to SmartyPanouZe3rd
    This is a follow-up to the above question I had.
    Since i noticed people looking at the question, but no replies showing up, i contacted BC support directly with the same question.
    I got a reply.
    I did tests based on the reply.
    Here is what is going on based on the reply.
    (spoiler alert : It works... but it's not yet a perfect score.)
    All the details are posted here :
    http://www.animavdo.com/mut/ambiguity-001.html
    Hope this can help others.
    Cheers.
    PS  I still will use DW for the heavy lifting...
           But MUSE is nice for quickly putting together a mini website.
           Highly recommended App.

  • Clicking on a link to open a new page or tab gives me a blank page.

    If I click on a link to open a new page or a new tab, the page that opens is always blank and no address is in the address bar. Also, occasionally, my refresh button is "grayed" out so I can't hit that either. I think this is some sort of security setting blocking it. Can anyone help.

    Thanks Jason, I had the same problem and did exactly the steps above. Problem solved! You rock! :)

  • How do i set what opens when I click on the "+" tab and open a new tab?

    I installed some sw for a camcorder and it changed something in FF. Now everytime I open a new tab, I get sent to this page;
    http://www.somoto.com/441/%7B9149BBF6-F330-44B5-8E1C-F9F70DD50517%7D?s_src=newtab
    How do I set it to not go anywhere when I open a new tab

    Not the home page, it is a new tab, but will most likely need cleaning up ''after'' fixing source of problem.
    If you have an extension named "NewStart" uninstall it (question [https://support.mozilla.com/questions/856436 856436]). If you don't you will have to identify the cause of the problem.
    After it is uninstalled check your about config filtering on '''somoto''' note any legitimate items seen there such as your old home page make a note, then delete every item with '''somoto''' (unless listed with a lot of other sites, such as sites to be blocked in the values, see Xircal's replies in [https://support.mozilla.com/en-US/questions/856436 856436])
    Also see pictures with [https://support.mozilla.com/questions/812137 812378]
    Fix your homepage afterwards
    :https://support.mozilla.com/kb/How+to+set+the+home+page
    If you have the Adblock Plus extension create a filter to prevent bringing up that site again create a filter. "||somoto.com/^" (without the quotes)
    :See http://www.mozillazine.com/Adblock
    Probably have no effect on this but do make sure that you have
    :'''Tools > Options > Security'''
    :[x] Warn me when sites try to install add-ons
    :[x] Block reported attack sites
    :[x] Block reported web forgeries
    :'''Exceptions:''' (for add-ons)
    : addons.mozilla.org Allow

  • Problem with Javascript and opening a new page

    Hi,
    I'm developping a website with Java Server Faces.
    I've a problem with JavaScript.
    I have a table, and each row of that table, has a button, to display more information about that specific row. I want to display this information in a new window. For this I want to use JavaScript.
    The new window, of course, needs some information of the other window, to show the right data.
    The first time I click the 'more-information-button', it works perfectly, but from than on, he keeps showing the same information...
    Here is my jsp-page of the first page (the one with the table):
    <?xml version="1.0" encoding="UTF-8"?>
    <jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page">
        <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
        <f:view>
             <f:loadBundle basename="languages.MessageBundle" var="bundle"/>
            <html>
                <head>
                    <meta content="no-cache" http-equiv="Cache-Control"/>
                    <meta content="no-cache" http-equiv="Pragma"/>
                    <title>- UCV-Period -</title>
                    <link href="resources/stylesheet.css" rel="stylesheet" type="text/css"/>
                </head>
                <body style="-rave-layout: grid">
                        <h:dataTable binding="#{UcvPeriod.dataTable1}" headerClass="list-header" id="dataTable1" rowClasses="list-row-even,list-row-odd" rows="5"
                            style="left: 24px; top: 168px; position: absolute" value="#{UcvPeriod.dataTable1Model}" var="currentRow">
                            <h:column binding="#{UcvPeriod.column1}" id="column1">
                                <h:outputText binding="#{UcvPeriod.outputUcvPeriod}" id="outputUcvPeriod" value="#{currentRow['UCVPERIOD']}"/>
                                <f:facet name="header">
                                    <h:outputText binding="#{UcvPeriod.outputText2}" id="outputText2" value="#{bundle.ucvPeriod_columnHeader_ucvPeriod}"/>
                                </f:facet>
                            </h:column>
                            <h:column binding="#{UcvPeriod.column11}" id="column11">
                                <h:commandButton action="#{UcvPeriod.btnDetails_action}" binding="#{UcvPeriod.btnDetails}" id="btnDetails" value="+" onclick="window.open('Details.jsp')"/>
                                <f:facet name="header">
                                    <h:outputText binding="#{UcvPeriod.outputText21}" id="outputText21" value=""/>
                                </f:facet>
                            </h:column>
                        </h:dataTable>
                    </h:form>
                </body>
            </html>
        </f:view>
    </jsp:root>Here is my action, when someone clicks on the 'more-information-button':
    public String bthnDetails_action() {
       Object s = outputUcvPeriod.getValue();
       BigDecimal ucvPeriod = (BigDecimal)outputUcvPeriod.getValue();
       this.getSessionBean().setUcvPeriod(new Integer(ucvPeriod.intValue());
       return "detail_ucvperiod";
    }Here is my constructor of the Detailspage.
        public Details() {
             this.txtUcvPeriod.setValue(this.getSessionBean().getUcvPeriod());
        }Here is the navigation part for this part of my faces-config.xml .
    <navigation-rule>
       <from-view-id>/UcvPeriod.jsp</from-view-id>
       <navigation-case>
           <from-outcome>detail_ucvperiod</from-outcome>
           <to-view-id>/UcvPeriod.jsp</to-view-id>
       </navigation-case>
    </navigation-rule>Thx a lot....
    Anneke

    See the tutorial "Sharing Data Between Two Pages" at http://devservices.sun.com/premium/jscreator/standard/learning/tutorials/data_sharing_twopages.html and the FAQ "How can I pass data between pages without creating SessionBean variables in Creator?" at http://devservices.sun.com/premium/jscreator/standard/reference/faqs/technical/javasource/passing_data.html. Since you can open a new window when your button is clicked, the tutorial and FAQ will explain ways to pass your data to the new window.

  • Need help on filtering out one record from a report and open in new page

    Hi I am new and embarrassed to write in the forum asking silly questions. Thing is I am learning all from scratch without help from anyone. I have created a database (have previous knowledge only from Access) and have managed to create a beautiful report from a search filter. This report lines up several records matching what I needed. Now, I want to make the whole report with hyperlinks to a detailed page on each of the records in the report. I have tried using the feature where one can make one column hyperlinked and redirect to a new page, where I am getting all the records again - instead of only getting the record I am clicking on. I have looked and looked in the forums without finding solution and I have tested and tried various methods without luck. I am suspecting that I need some sort of knowledge on how to write a select query with where conditions that can apply to filtering out a record from one report to get another detailed on only one object (i.e. record). :/ Stupid or what?

    Hrefna.
    What you need to look into is two things:
    1) The link you defined, needs to set additional attributes for the target page. In the "Column Link" box, you have set the link to "Page in this Application" and followed by the page number (let's say, Page 10). Below that, you should set an Item to an item on you target page (let's call that P10_PRODUCT_ID). This item should be the primary key of your detail table (on the targe page). You can select this item from the popup list. The Value of the item should be picked from a popup list as well, being the value from the record you clicked on. This should then transfer your selected item to your page. The URL will then have something like P10_PRODUCT_ID:5 at the end.
    2) On the target page, 10, you must change the query slightly, so that it adds a WHERE clause:
    WHERE PRODUCT_ID = :P10_PRODUCT_ID
    Now, you should be set.
    Hope this helps.
    Borkur

  • Problem with opening new tabs, when I right-click on a link and open in new tab it doesn't automatically load up like firefox 3.6 always did. Is there anyway to fix this?

    for example there's a link a friend sent me in my e-mail and I right-click on it, and select "Open in a new tab" it pops open like normal, except it does not load the page, I have to click the box and press enter to even get it to load it. In previous versions I have never had that problem, current version of Mozilla Firefox I am using is version 4, previous was 3.6 hope this helps figure this out.

    You can middle-click a link to open the link in a new tab.
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode

  • I am experiencing problems with my i phone due to sharing my daughters i tunes acoount. I have been told by apple to cancel my existing (shared) i tunes account and open a new one for my use only. How do I do this? Please help. RM

    I am experiencing on going problems with my i phone 4 due to me sharing an i tunes account with my daughter. I have been told by apple to cancel my existing (shared) i tunes account and open a new one for my use only. How do I do this? I cant find any links in i tunes to do this. mountfield

    No, it's done on the computer, it's just done on the web and not through iTunes. I guess you could do it on the iPhone, but it would be easier to do on the computer.
    Just go to the site linked above, then click on the big blue button and fill out the neccessary information.

  • How to open a new page from a Spry Table click, with element info?

    Hello, Spry experts!
    This is probably simple, but I've searched for hours and can't find what I need. I'm using Dreamweaver CS4 and Spry 1.6.1 to create a simple Spry Table from an XML data set using PHP as my back end.  I've used Dreamweaver's Insert->Spry->Spry Data Set to create everything, and the table is working fine.  Colors, clicks, sorts, etc., are all working correctly as expected.
    What I want is to be able to add a behavior such that when a table row is clicked, I can open a new page.  Moreover, I want to pass a parameter from the table to the new page, like http://www.mydomain.com/newpage.php?aid=12345 or whatever.
    So, for example, my table has two columns, "a_id" and "a_name", and my repeat region looks like this:
    <div spry:region="xml_assignments">
    <table width="500">
    <tr>
    <th spry:sort="a_id" class="spry_header">ID</th>
    <th spry:sort="a_name" class="spry_header">Assignment</th>
    </tr>
    <tr spry:repeat="xml_assignments" spry:setrow="xml_assignments" spry:odd="spry_odd" spry:even="spry_even" spry:hover="spry_hover" spry:select="spry_select">
    <td>{a_id}</td>
    <td>{a_name}</td>
    </tr>
    </table>
    </div>
    What I want is to be able to open an entirely new URL, passing the value of the {a_id} in the selected row as a parameter to the new URL, as in something like:  http://www.mydomain.com/newpage.php?aid={a_id}
    So my questions are: 
    1. How best to apply the action to the table?  Add an onclick to the tr tag?  Something else?
    2. How to extract the {a_id} value from the current row and pass it as a parameter to the action?
    Or maybe just take another approach entirely?
    I know that I can make the actual text in the table cells hyperlinks, and use them to link to the new page, which is fine.  The desire here is just to make it so that the user can click "anywhere" on the table row (as they can currently do with the spry:select behavior) and have the link kick off, whether they actually click on the linked text or somewhere in the row where there is no text.
    I'm sure this is obvious and simple, but I'm new to this level of Spry detail, and my brain is fried from hunting.  Any guidance will be gratefully appreciated!
    Glen Barney

    I found the answer myself, after posting this, of course!
    I changed:
    <tr spry:repeat="xml_assignments" spry:setrow="xml_assignments" spry:odd="spry_odd" spry:even="spry_even" spry:hover="spry_hover" spry:select="spry_select">
    to
    <tr spry:repeat="xml_assignments" spry:setrow="xml_assignments" spry:odd="spry_odd" spry:even="spry_even" spry:hover="spry_hover" spry:select="spry_select" onclick="window.location.href='./newpage.php?aid={a_id}';">
    Basically just added the onclick parameter...
    And it all just worked!

  • All of a sudden I can no longer open tabs by clicking "+" or right clicking on the tool bar. To open a new page, I have to open a whole newFirefox window. How can I fix this?

    All of a sudden I can no longer open tabs by clicking "+" or right clicking on the tool bar. To open a new page, I have to open a whole new Firefox window. How can I fix this?
    Also, Firefox crashes frequently. Is there a fix for this also?

    Uninstall the Ask toolbar and it should work again. There is a compatibility issue with the Ask toolbar and Firefox 3.6 that prevents new tabs from being opened.
    There are a couple of places to check for the Ask toolbar:
    * Check the Windows Control panel for the Ask Toolbar - http://about.ask.com/apn/toolbar/docs/default/faq/en/ff/index.html#na4
    * Also check your list of extensions, you may be able to uninstall it from there - https://support.mozilla.com/kb/Uninstalling+add-ons
    For the second issue, the [[Firefox crashes]] support article may help.

  • In a Google search, clicking on a search result causes the new page to open with the search terms highlighted in yellow -- how can I turn off th

    In a Google search within a Firefox session, clicking on a search result causes the new page to open with the search terms highlighted in yellow -- how can I turn off this highlighting?

    Try to clear the Google cookies and redo those Google options.
    * "Remove the Cookies" from sites causing problems: Tools > Options > Privacy > Cookies: "Show Cookies"

  • Photos in album are only a hash-marked outline the image only shows when scrolling how can I see the image and open the photo?

    Photos in iPhoto album are only a hash-marked outline the image only shows when scrolling how can I see the image and open the photo?

    Make a temporary, backup copy (if you don't already have a backup copy) of the library and apply the two fixes below in order as needed:
    Fix #1
    Launch iPhoto with the Command+Option keys held down and rebuild the library.
    Select the options identified in the screenshot. 
    Fix #2
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    Download iPhoto Library Manager and launch.
    Click on the Add Library button, navigate to your Home/Pictures folder and select your iPhoto Library folder.
    Now that the library is listed in the left hand pane of iPLM, click on your library and go to the File ➙ Rebuild Library menu option
    In the next  window name the new library and select the location you want it to be placed.
    Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments but not books, calendars or slideshows. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.
    OT

  • How can I set up new sites to open in new pages and not over the top of the current open page?

    how can I set up new sites to open in new pages and not over the top of the current open page?

    Middle-click ''(press down mouse scroll wheel)'' <br />
    or <br />
    {Ctrl + Click} <br />
    or <br />
    Right-click and use '''''Open in a New Tab'''''

  • Everytime I open a new page in firefox a you tube video keeps opening and playing, how do I stop this?

    I had clicked on a you tube video accidentally and now, everytime I open a new page the video comes up. How can I make this stop?

    Check the Home page setting.
    *https://support.mozilla.org/kb/How+to+set+the+home+page

  • I shall open delete my present account with iTunes and open a new one - but I do not have the password. How can I then delete the present account??

    I shall open delete my present account with iTunes and open a new one - but I do not have the password. How can I then delete the present account??

    Since you can't delete Apple IDs and having multiple Apple IDs can cause confusion, what you may want to do is rename your existing Apple ID to the new email (desired Apple ID).  That would in effect do what you want, get rid of the old and give you the new.
    See "Apple ID: Changing your Apple ID"
    ivan

Maybe you are looking for