Popups in Struts framework

Discussions

Web tier: servlets, JSP, Web frameworks: Popups in Struts framework

  1. Popups in Struts framework (3 messages)

    Hi,

    In a situation like, there is a text box and a browse kind of button. When the user hits the button, a popup should come and depending on selection in the popup the text box should be populated. How to handle such kind of situation in Struts framework? Do I need to resort to Javascript?

    Thanks

    Suresh

    Threaded Messages (3)

  2. Popups in Struts framework[ Go to top ]

    You could conceivably do this server-side, but is a waste of a roundtrip, and of Java code, when it can easily be client-side.

    With Javascript, this is incredibly simple. Here is the main page for an example:

    ______________________________________________________________

    <form name=popupform>
    <input type="button" name="chooser" onClick="window.open('popup.html','popup','width=250,height=200,top=100,left=100');" value="Choose WebSite"><br>
    <input type="text" name="choice" value=""/>
    </form>
    ______________________________________________________________
    And here is the popup page, 'popup.html'
    ______________________________________________________________
    <html>
    <head>
    <script language="JavaScript">
    //set the value in the parent page
    function sendValue(s){
    var selvalue = s.options[s.selectedIndex].value;
    window.opener.document.popupform.choice.value = selvalue;
    window.close();
    }
    </script>
    </head>
    <body>
    <center>
    <form name="selectform">
    <select name=selectmenu size="3">
    <option value="The" rel="nofollow">http://www.theserverside.com">The ServerSide.com
    <option value="The" rel="nofollow">http://www.theserverside.net">The ServerSide.net
    <option value="java.net" rel="nofollow">http://java.net">java.net
    </select>
    <br/>
    <input type=button value="Item Select Item" onClick="sendValue(this.form.selectmenu);">
    </form>
    </center>
    </body>
    </html>
    ______________________________________________________________

    Regards,
      Trevor
  3. Popups in Struts framework[ Go to top ]

    Thanks Trevor for your reply. I had posted this message because, MVC2 architecture tries to avoid javascript(which may be good). So trying to find a solution what struts framwork provides.

    regards

    Suresh
  4. Popups in Struts framework[ Go to top ]

    Thanks Trevor for your reply. I had posted this message because, MVC2 architecture tries to avoid javascript(which may be good). So trying to find a solution what struts framwork provides.regardsSuresh
    JavaScript is still necessary to open the popup window even if you make a trip back to the server. I've used the onLoad() event of the <BODY> to call a JavaScript method which opens a popup window.

    If you wanted to avoid JavaScript altogether, use layers <div> with the server code determining if the layer is visible. The layer can be made to look like a custom popup. But then you'll still need JavaScript to hide the layer (close the popup).