Working with Pop-Up windows

Hi,

heres my requirement:

To open a pop-up window onclick of a link from the parent window. Parent window has a data-table and a column called 'StatementInfo' which shows the statementNumber as a h:commandLink. When i click on the statement number i want to show the details of that statement in the pop-up. The details are rendered as a dataTable and if i am able to pass this statementNumber then i need to render the dataModel for that statementNumber.

If i have not made myself clear, heres a simpler example;

You have a page where you list all employees in a datatable. the employee id is a commandLink. I want to show the employee details when user clicks this link. Possible if so how and if there are any examples please point me to them.

Has any one done this before? I am using RAD6.0 and jsf1.0.1. I wouldnt want to use any apache component though.

thanks in advance,

Dilip

[936 byte] By [dilip_jsfa] at [2007-11-27 11:19:51]
# 1

Use Javascript to create a popup window pointing to a JSF page and in the JSF page just call the backing bean where the row object is stored. Then show it's details.

BalusCa at 2007-7-29 14:39:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

If i use the parent windows pagecode to render the pop-up windows dataTable, how will i get that row detail? Using getRowData() method? To use this should i not be doing a submit of the parent page? And if i do submit the parent page, i will lose all the info in that page.

dilip_jsfa at 2007-7-29 14:39:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

If you don't want to invoke a post on the mainpage, then pass a parameter to the popup window indicating the row clicked.

BalusCa at 2007-7-29 14:39:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Ok, even if i pass the parameter to the pop-up page , how do i get that ID in the pagecode so that i can get the details for that row and populate the dataTable accordingly?

dilip_jsfa at 2007-7-29 14:39:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

I dont understand how to do this. If you can point me to some example or provide me with some code assistance wouyld be helpful.

meanwhile here is what i tried:

mainPage.jsp

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>

<html>

<script type="text/javascript" language="javascript">

function openPopUp(link) {

var winId = window.open("popUp.jsp","window","left=30,top=20,width=800,height=600,resizable=no,scrollbars=1,status:no");

link.onclick();

return false;

}

</script>

<body>

<f:view>

<h:form id="mainPageForm">

<h:dataTable id="dataTableOne" value="#{pc_mainPage.dataModel}" var="e">

<h:column id="col1">

<f:facet name="header">

<h:outputText value="Employee ID" id="empIDHeader"/>

</f:facet>

<h:commandLink onmousedown="return openPopUp();">

<h:outputText value="#{e.employeeID}" />

</h:commandLink>

</h:column>

<h:column id="col2">

<f:facet name="header">

<h:outputText value="Employee Sex" id="empSexHeader"/>

</f:facet>

<h:outputText value="#{e.employeeSex}" />

</h:column>

</h:dataTable>

</h:form>

</f:view>

</body>

</html>

popUp.jsp

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<html>

<body>

<f:view>

<h:form id="popUpForm">

<h:dataTable id="dataTableTwo" value="#{pc_mainPage.dataModelPop}" var="e">

<h:column id="ncol1">

<f:facet name="header">

<h:outputText value="Employee ID" id="pempIDHeader"/>

</f:facet>

<h:outputText value="#{e.employeeID}" />

</h:column>

<h:column id="ncol2">

<f:facet name="header">

<h:outputText value="Employee Sex" id="pempSexHeader"/>

</f:facet>

<h:outputText value="#{e.employeeSex}" />

</h:column>

<h:column id="ncol3">

<f:facet name="header">

<h:outputText value="Employee Name" id="pempNameHeader"/>

</f:facet>

<h:outputText value="#{e.employeeName}" />

</h:column>

<h:column id="ncol4">

<f:facet name="header">

<h:outputText value="Employee Age" id="pempAgeHeader"/>

</f:facet>

<h:outputText value="#{e.employeeName}" />

</h:column>

</h:dataTable>

</h:form>

</f:view>

</body>

</html>

common page code for both.

package pagecode;

import java.util.ArrayList;

import javax.faces.model.DataModel;

import javax.faces.model.ListDataModel;

public class MainPage {

//Main page data model

private DataModel dataModel = new ListDataModel();

//opo-up page data model

private DataModel dataModelPop = new ListDataModel();

public DataModel getDataModel() {

ArrayList list = new ArrayList();

Employee emp = new Employee();

emp.setEmployeeAge("23");

emp.setEmployeeID("200");

emp.setEmployeeName("DA");

emp.setEmployeeSex("Male");

Employee emp1 = new Employee();

emp1.setEmployeeAge("24");

emp1.setEmployeeID("300");

emp1.setEmployeeName("RM");

emp1.setEmployeeSex("Female");

Employee emp2 = new Employee();

emp2.setEmployeeAge("23");

emp2.setEmployeeID("400");

emp2.setEmployeeName("JP");

emp2.setEmployeeSex("Male");

Employee emp3 = new Employee();

emp3.setEmployeeAge("22");

emp3.setEmployeeID("500");

emp3.setEmployeeName("VT");

emp3.setEmployeeSex("Male");

list.add(emp);

list.add(emp1);

list.add(emp2);

list.add(emp3);

this.dataModel.setWrappedData(list);

setDataModel(this.dataModel);

return this.dataModel;

}

public void setDataModel(DataModel dataModel) {

this.dataModel = dataModel;

}

public DataModel getDataModelPop() {

Employee emp = (Employee) this.getDataModel().getRowData();

ArrayList arrayList = new ArrayList();

arrayList.add(emp);

this.dataModelPop.setWrappedData(arrayList);

return dataModelPop;

}

public void setDataModelPop(DataModel dataModelPop) {

this.dataModelPop = dataModelPop;

}

}

My pop-up page gets the first employee details only. Dunno how to get the ID from the mainPage into the pop-up and use the same to populate it in the pop-up page.

thanks,

Dilip

dilip_jsfa at 2007-7-29 14:39:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...