Hello All,
I am working on
JSF since 2 months . I have a need in project such that if I open a popup calling the same
JSP again , I need to generate the components as per the condition and store the values and close the window . This is just an sample , truly speaking I need to generate many components in popup while calling the same JSP. The Problem I am facing now is , I can see the same Parent window components when I open the popup.Its not showing the new PanelGrid. From Parent window to nth popup window , we are going to store values in Same object in sessionScope.
Can some one help me in fixing this issue . As I am stuck at work to proceed further.
The Below is just a sample of my application scenario.
Code :
ToTest.jsp=====>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%-- jsf:pagecode language="java" location="/src/pagecode/pages/ToTest.java" --%><%-- /jsf:pagecode --%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>Totest</title>
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/styles/style.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
<link rel="stylesheet" type="text/css" href="../theme/stylesheet.css"
title="Style">
</head>
<f:view>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<hx:scriptCollector id="scriptCollector1">
<h:form id="DynamicUIform" styleClass="form" >
<h:panelGrid binding="#{pc_ToTest.htmlPanelGrid}"
></h:panelGrid>
</h:form>
</hx:scriptCollector>
</body>
</f:view>
</html>
===========================================================================
ToTest.java ( Backing Bean)
/**
*
*/
public class ToTest extends PageCodeBase {
public HtmlPanelGrid htmlPanelGrid = null;
protected HtmlForm DynamicUIform;
private FacesContext facesContext = null;
private Application application = null;
protected HtmlScriptCollector scriptCollector1;
protected HtmlCommandExButton button1;
public HtmlPanelGrid gethtmlPanelGrid() {
//if (htmlPanelGrid == null) {
//htmlPanelGrid = new HtmlPanelGrid();
//
//System.out.println("new html object created");
//}
htmlPanelGrid = new HtmlPanelGrid();
System.out.println("called gethtml method of Totest"+ htmlPanelGrid);
testComponent();
return htmlPanelGrid;
}
public void sethtmlPanelGrid(HtmlPanelGrid htmlPanelGridd) {
System.out.println("Called sethtmlPanelGrid of totest.");
this.htmlPanelGrid = gethtmlPanelGrid();
//this.htmlPanelGrid = htmlPanelGridd;
System.out.println("Finished sethtmlPanelGrid of to test." +htmlPanelGrid);
}
public void testComponent() {
String testing=" ";
System.out.println("entered
test component method");
Application application = FacesContext.getCurrentInstance()
.getApplication();
facesContext = FacesContext.getCurrentInstance();
//facesContext.getViewRoot().setTransient(true);
htmlPanelGrid.getChildren().clear();
try{
System.out.println("entered try block");
testing = (String) facesContext.getExternalContext()
.getRequestParameterMap().get("sessionPath");
System.out.println("Testing "+ testing );
}catch(Exception e){
e.printStackTrace();
}
if(this.getSessionScope().get("Reference")==null){
this.getSessionScope().put("Reference", new Reference());
System.out.println("created Reference obj in session");
}else{
System.out.println("already Reference in session");
}
System.out.println("Choice is "+choice);
htmlPanelGrid.setColumns(2);
if ( testing !=null && testing.equals("one")){
HtmlOutputLabel arrestType = new HtmlOutputLabel();
arrestType.setValue("ArrestType");
HtmlInputText htmlInputText = new HtmlInputText();
ValueBinding InenameBinding = application
.createValueBinding("#{sessionScope.Reference.arrestType}");
IntegerConverter conv = new IntegerConverter();
htmlInputText.setConverter(conv);
htmlInputText.setValueBinding("value", InenameBinding);
htmlPanelGrid.getChildren().add(arrestType);
htmlPanelGrid.getChildren().add(htmlInputText);
System.out.println("executed if block");
}else{
HtmlOutputLabel officerId = new HtmlOutputLabel();
officerId.setValue("OfficerId");
HtmlInputText htmlInputText1 = new HtmlInputText();
ValueBinding lnameBinding = application
.createValueBinding("#{sessionScope.Reference.officerId}");
htmlInputText1.setId("officerId");
htmlInputText1.setValueBinding("value", lnameBinding);
htmlPanelGrid.getChildren().add(officerId);
htmlPanelGrid.getChildren().add(htmlInputText1);
System.out.println("executed else block");
}
HtmlCommandButton submitButton = new HtmlCommandButton();
submitButton.setValue("Submit Button");
MethodBinding submitButtonBinding = application.createMethodBinding(
"#{pc_ToTest.doSubmitTest}", null);
submitButton.setAction(submitButtonBinding);
htmlPanelGrid.getChildren().add(submitButton);
String javaScriptText = "window.open('"
+ "ToTest.faces"
+ "?sessionPath="
+ "one"+ "', '\', 'status=1,width=750,height=450,scrollbars=yes,resizable=no,modal=yes');return false;";
HtmlCommandButton submitButton1 = new HtmlCommandButton();
submitButton1.setValue("Popup window ");
submitButton1.setOnclick(javaScriptText);
htmlPanelGrid.getChildren().add(submitButton1);
System.out.println("end of test component method");
}
public String doSubmitTest() {
System.out.println("From method getSubmitTest");
// System.out.println("page level"+ pageLevel);
return "testpage";
}
}