Open a new page when I click on a JSF table

butterolessen

New Member
I have this `h:outputLink' which I use to open a new page when I click on a JSF table row:\[code\]<h:outputLink id="lnkHidden" value="http://stackoverflow.com/questions/15862387/page.html" style="text-decoration:none; color:white;"> <f:param name="id" value="http://stackoverflow.com/questions/15862387/#{item.value}" /></h:outputLink>\[/code\]I use this JavaScript to open a new page when I click on a row:\[code\]// For clicking on a row and opening new pagefunction addOnclickToDatatableRows() { //gets all the generated rows in the html table var trs = document.getElementById('form: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++) { var cells = trs.cells; for(var j=1; j < cells.length; j++){ cells[j].onclick = new Function("rowOnclick(this.parentElement)"); } }}function rowOnclick(tr) { var elements = tr.cells[0].childNodes; for(var i = 0; elements.length > i; i++) { if ((typeof elements.id != "undefined") && (elements.id.indexOf("lnkHidden") > -1)) { location.href=http://stackoverflow.com/questions/15862387/elements.href; break; } } return false;}\[/code\]I updated the code this way:\[code\]<h:commandLink id="lnkHidden" style="text-decoration:none; color:white;" actionListener="#{bean.pageRedirect}"> <f:setPropertyActionListener target="#{bean.sessionValue}" value="http://stackoverflow.com/questions/15862387/#{item.value}" /></h:commandLink>\[/code\]managed bean:\[code\]public void setSessionValue(Object value) { ........... }public String pageRedirect() { return "/DatacenterProfile.html"; }\[/code\]It turns out that the JavaScript is nit working properly because I changed to \[code\]h:commandLink\[/code\]. Can you help me to fix this problem?
 
Back
Top