Adding a Popup Window to a NetBeans 6.0 Visual Web Page

Here is a mini-tutorial for creating a Popup window for the user to lookup values. One scenario that you might use this for is when the page visitor needs more information then can be displayed in a drop-down list.

This is a rewrite of a previous blog entry that was written for the Sun Java Studio Creator IDE. I have modified the steps so that it works for the NetBeans 6.0 IDE.

  1. Create a web application project with the Visual Web JavaServer Faces framework.

  2. Add a page named Popup.

  3. Add a Table component to the page.

  4. Drag VIR > Tables > State from the Services window and drop it on the table.

  5. Right-click the Table component and choose Table Layout from the pop-up menu.

  6. In the column for the STATE.STATEID database field, set the Component Type to Hyperlink, and click OK.

  7. Select the Hyperlink component so that its properties appear in the Properties window.

  8. Set the value for the onClick property to doSave('#{currentRow.value['STATE.STATEID']}')

    (I got the value to pass to doSave() from the Value Expression in the Table Layout dialog).

  9. Drag a Script component from the Advanced section of the Palette and drop it on the page.

  10. Click JSP in the editing toolbar to view the JavaServer Pages script.

  11. In the JSP page, change the <webuijsf:script> tag as shown below.

    <webuijsf:script binding="#{Popup.script1}" id="script1">
    function doSave(val) {

    The Popup page is now ready for use by another page.

  12. Create a new page called Form1. Make it be the start page.

  13. Drag a Text Field component and drop it on the page. In the Properties window, make sure the id is set to textField1.

  14. Drop a Hyperlink component on the page, just above the text field, and set the text property to State Code.

  15. Set the url property to /faces/Popup.jsp.

  16. Set the onClick property to doPopup('form1:textField1_field')

    Note: Here you are passing the id of the field to fill with the selected value. Determining the id can be tricky. To determine what to use for the id, run the application, and use a tool such as Firebug to inspect the DOM.

  17. Click the ... button for the target property to open the target property editor.

  18. In the property editor, click New and set both the Display and Value to popup. Click OK and click OK again.

    Later you add script to open a window named popup, and this setting causes the Popup.jsp page to display in that window.

  19. If the target property value is still blank, select popup from the value from the combobox for that property.

  20. Drag a Script component from the Advanced section of the Palette and drop it on the page.

  21. Click JSP in the editing toolbar to view the JavaServer Pages script.

  22. In the JSP page, change the <webuijsf:script> tag as shown below.

    <webuijsf:script binding="#{Form1.script1}" id="script1">
    function doPopup(destination) {
     popup ="", "popup",
     "height=300,width=200,toolbar=no, menubar=no,scrollbars=yes");
    function setVal(val){

  23. Run the project. Click State Code to open the popup window. Click a state code to select the code, close the popup window, and populate the text field.

This is good tutorial.
I have a question.
In doPopup function ,i think ,you use the client identifier of TextField.
As i know from "JSF in Action",the client identifier of TextField must be "form1: textfield1" not "form1:textField1_field".
Can you explain what the _field is?
And also i looked at the source of the page (from browser) and i do not find neither a input element with id form1:textField1_field and nor with id
I am confusing.
Thanks in advance.

Posted by guest on January 04, 2008 at 04:14 AM PST #


You are correct that there is no input html element in the page source. Instead there is "dojo.addOnLoad(function() {webui.suntheme.widget.common.replaceElement("form1:textField1", {"widgetType":"webui.suntheme.widget.textField","value":"","required":false,"disabled":false,"style":"left: 24px; top: 72px; position: absolute","visible":true,"valid":true,"size":20,"readOnly":false,"id":"form1:textField1","autoValidate":false});});"
That is why I say to inspect the DOM. It is not sufficient to look a the page source.

The NetBeans Visual Web components are enhanced JSF components and thus the rule that you site from JSF in Action does not fully translate to Visual Web components. A Visual Web text field component is actually three html elements -- a span with nested span (label) and input elements - each with a unique id. If you inspect the DOM, you will see a structure like this:

Parent: span form1:textField1

First Child: span form1:textField1_label

Second Child: input form1:textField1_field

Posted by Diva #2 on January 04, 2008 at 05:02 AM PST #


This sample dont work properly in Netbeans 6 we must replace setVale method with this method :

function setVal(val){

best regard


Posted by Saeed on January 04, 2008 at 12:22 PM PST #

Hello Saeed,

Thank you for your comment. I tested this using NetBeans IDE 6 and both Firefox and IE, and it works on both. Can you better define "doesn't work properly" and state what browsers you are testing on?

Posted by Diva #2 on January 07, 2008 at 01:37 AM PST #

good work

Posted by guest on January 08, 2008 at 12:56 PM PST #


setVal() function does not work in Netbeans 6 and firefox browser.

because JSF componentn in Netbeans 6 are different from Netbeans 5.5 .

we must replace setVale method with this method :

function setVal(val){

Posted by Saeed on January 08, 2008 at 01:40 PM PST #

Very Goooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooood

Posted by guest on January 09, 2008 at 04:25 PM PST #

buen dia.

tengo un pequeño problemita y no sabia en donde pedir ayuda,

como le agrego un color de fondo a una caja de texto con vwp,
no funciona dandole style ni agregando una classname ni sobreescribiendo esta clases tomadas del ColorandMedia.css

no se que mas hacer el diseñador de la empresa me esta hechando el proyecto que quiero hacer con esta tecnologia pero por esta bobada me tiene muy pero muy mal

agradezco cualquier ayuda

Posted by Jaider Rdoriguez on April 20, 2008 at 02:33 AM PDT #


I am afraid that I do not know much about setting styles and such. You should read Winston's blog, He has some good tips on the subject.

Posted by guest on April 21, 2008 at 02:39 AM PDT #


Tenia problemas por q estaba trabajando en netbean6
pero cambie la funcion setVal como mencionan y trabaja de maravilla

Sin embargo me muestra el siguiente Warning en la consola del tomcat

WARNING: executePhase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@7f641e) threw exception
at com.sun.faces.lifecycle.RenderResponsePhase.execute(
at com.sun.faces.lifecycle.LifecycleImpl.phase(
at com.sun.faces.lifecycle.LifecycleImpl.render(
at com.sun.faces.extensions.avatar.lifecycle.PartialTraversalLifecycle.render(
at javax.faces.webapp.FacesServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at com.sun.webui.jsf.util.UploadFilter.doFilter(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.Http11Processor.process(
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
Caused by: ClientAbortException: Broken pipe
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(
at org.apache.catalina.connector.OutputBuffer.doFlush(
at org.apache.catalina.connector.OutputBuffer.flush(
at org.apache.catalina.connector.Response.flushBuffer(
at org.apache.catalina.connector.ResponseFacade.flushBuffer(
at javax.servlet.ServletResponseWrapper.flushBuffer(
at com.sun.faces.application.ViewHandlerImpl.renderView(
at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView(
at com.sun.faces.lifecycle.RenderResponsePhase.execute(
... 22 more
Caused by: Broken pipe
at Method)
at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(
at org.apache.tomcat.util.buf.ByteChunk.append(
at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(
at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(
at org.apache.coyote.http11.InternalOutputBuffer.doWrite(
at org.apache.coyote.Response.doWrite(
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(
... 31 more

Alquien sabe a que se debe este error?

Posted by Roger on May 02, 2008 at 01:34 AM PDT #


Is the Tomcat a J2EE server?

Posted by diva #2 on May 02, 2008 at 11:37 AM PDT #

Tomcat is not a full J2EE server.
but, what do you want to say with this question?

Posted by Roger on May 11, 2008 at 11:42 PM PDT #

Hi Roger,

The components that you use on the Visual Web pages useJ2EE technology and can only be deployed to J2EE technology compliant servers, such as GlassFish.

Posted by diva #2 on May 12, 2008 at 02:43 AM PDT #


Posted by Omar on June 01, 2008 at 07:13 PM PDT #

Omar, see also I and others have successfully implemented this with IE, but none of us say which IE we used to test. I expect that in the original post (url above) I tested with IE6. Have you verified that it only doesn't work with IE6? That is, have you tested with IE7 and Firefox? It would help to determine what has changed with IE6 such that it didn't work then abut works now with IE7 (if indeed such is the case).

Posted by diva#2 on June 02, 2008 at 02:18 AM PDT #


i'd like to write the selected value from the popup to a tablecell. i don't know how to get the correct destination.

i think i have to change something here: doPopup('form1:textField1_field')...but i don't know how.

does anybody have any idea?

Posted by Fu on July 06, 2008 at 06:35 PM PDT #


I have never come up with a solution for writing the selected value into a table row. Maybe think about another solution such as dynamic faces, ajax code completion?

Posted by guest on July 08, 2008 at 03:45 AM PDT #

Hi All,
the link "" seems to be broken.
Does anybody know the correct url ?
Thanks anyway ...

Posted by Barney on September 02, 2008 at 07:17 PM PDT # works fine for me

Posted by guest on September 02, 2008 at 08:51 PM PDT #

Post a Comment:
Comments are closed for this entry.



« July 2016