OK, I'm just going by the O'Reilly "JavaScript: The Definitive Guide" book, which says it uses the name. And I noticed (through doing an "assert" between each line of the JavaScript) that JavaScript recognizes the object hidden["hidden:country"], but it does not recognize (and therefore bombs out when referring to) hidden["hidden:go"]. I checked the rendered HTML, and the rendered anchor does have its id set to "hidden:go".
If anyone knows another reason why the JavaScript would recognize hidden["hidden:country"] but not hidden["hidden:go"], but then recognize hidden[1] when I replace hidden["hidden:go"] to hidden[1], I'd be interested in an explanation. But, even when I refer to the control using a numeric index, rather than using a name, the popup still doesn't work (see problem 2 in my original message). Any ideas? Has anyone used a different design for doing a JSF popup where the popup shares the same managed bean as the base page? - Brendan -----Original Message----- From: Dennis Byrne [mailto:[EMAIL PROTECTED] Sent: Friday, July 15, 2005 11:48 AM To: MyFaces Discussion Subject: Re: Doing Popup Windows Using JSF I promise the reason the "JavaScript in index2.jsp does not recognize hidden["hidden:go"]" will have nothing to do with the name attribute. Client side manipulation of form elements is going to be done with the id attribute. You might want to explore other explanations. ---- Original message ---- >Date: Fri, 15 Jul 2005 11:16:41 -0500 >From: "CONNER, BRENDAN \(SBCSI\)" <[EMAIL PROTECTED]> >Subject: Doing Popup Windows Using JSF >To: "MyFaces Discussion" <[email protected]> > >I am trying to launch a pop-up window using JSF, where the pop-up window >and base window share the same managed bean. There is an example of how >to do this in Sun's Core JavaServer Faces book (Chapter 12) that defines >two JSF pages that share a common managed bean: > >1. index2.jsp >2. popup2.jsp > >When one clicks on a command button in index2.jsp, it executes >JavaScript to launch a popup window, and then it submits a form that >puts popup2.jsp into the popup window. However, the code doesn't seem >to work. I list the code at the end of this e-mail. > >There are two problems with the code: > >1. From doing a "view source" on the generated HTML, I can see that HTML >anchor tag rendered by <h:commandLink> does not specify a name for the >control; it just specifies an id for the control. Therefore, the >JavaScript in index2.jsp does not recognize hidden ["hidden:go"] as a >valid object, since there is no control with the name "hidden:go" >(there's only a control with the *id* of "hidden:go"). I can bypass >this problem by referring to this control as hidden[1] instead of >hidden["hidden:go"], although that's kind of klugey. Still, that >eliminates that problem. The next problem is the real kicker. > >2. When the popup gets displayed, it is not populated with popup2.jsp. >Rather, it is populated with another copy of index2.jsp. Just in case >there were errors in index2.jsp, I tried using a blank JSP as the popup >JSP, but, again, the popup was populated with index2.jsp rather than the >blank JSP. > >Any ideas about why this doesn't work? I tried it using two different >JSF reference implementations (including MyFaces), but I get the same >errors. > > > >index2.jsp: > ><html> > <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" % > > <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" % > > > <f:view> > <head> > <script language="JavaScript1.1"> > function doPopup(source) { > country = source.form[source.form.id + ":country"]; > for (var i = 0; i < country.length; i++) { > if (country[i].checked) { > popup = window.open("", > "popup", > "height=300,width=200,toolbar=no,menu bar=no," > + "scrollbars=yes"); > popup.openerFormId = source.form.id; > popup.focus(); > var hidden = document.forms.hidden; > hidden["hidden:go"].value = "x"; // any value will >do > hidden["hidden:country"].value = country [i].value; > hidden.submit(); > } > } > } > </script> > <title>A Simple Java Server Faces Application</title> > </head> > <body> > <h:form> > <table> > <tr> > <td>Country:</td> > <td> > <h:selectOneRadio id="country" >value="#{bb.country}"> > <f:selectItem itemLabel="USA" itemValue="USA"/> > <f:selectItem itemLabel="Canada" >itemValue="Canada"/> > </h:selectOneRadio> > </td> > </tr> > <tr> > <td>State/Province:</td> > <td> > <h:inputText id="state" value="# {bb.state}"/> > </td> > <td> > <h:commandButton value="..." > onclick="doPopup(this); return false;"/> > </td> > </tr> > </table> > <p> > <h:commandButton value="Next" action="next"/> > </p> > </h:form> > > <%-- This hidden form sends a request to a popup window. --%> > <h:form id="hidden" target="popup"> > <h:inputHidden id="country" value="# {bb.country}"/> > <h:commandLink id="go" action="showStates" value=""> > <f:verbatim/> > </h:commandLink> > </h:form> > </body> > </f:view> ></html> > > >popup2.jsp: > ><html> > <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" % > > <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" % > > > <f:view> > <head> > <script language="JavaScript1.1"> > function doSave(value) { > var formId = window.openerFormId; > opener.document.forms[formId][formId + ":state"].value = >value; > window.close(); > } > </script> > <title>Select a state/province</title> > </head> > <body> > <h:form> > <h:dataTable value="#{bb.statesForCountry}" var="state"> > <h:column> > <h:outputLink value="#" > onclick="doSave('#{state}');"> > <h:outputText value="#{state}" /> > </h:outputLink> > </h:column> > </h:dataTable> > </h:form> > </body> > </f:view> ></html> > > > >faces-config.xml: > ><faces-config> > <navigation-rule> > <navigation-case> > <from-outcome>showStates</from-outcome> > <to-view-id>/popup2.jsp</to-view-id> > </navigation-case> > </navigation-rule> > > <managed-bean> > <managed-bean-name>bb</managed-bean-name> > <managed-bean-class>com.corejsf.BackingBean</managed- bean-class> > <managed-bean-scope>session</managed-bean-scope> > </managed-bean> ></faces-config> > > >- Brendan > Dennis Byrne

