aspose file tools*
The moose likes Struts and the fly likes how to create a 'diaolg'? bttn that open a  new-win ->when closed - rtrn to main form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to create a Watch "how to create a New topic
Author

how to create a 'diaolg'? bttn that open a new-win ->when closed - rtrn to main form

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi there,

I have the following form fields:
1. name of contract
2. description
3. date start
4. date end
5. approvers*

the approvers is a list of users that must approve the contract. My question is how should I design such a form, so when the end-user clicks the approver's button, a new window will pop up with the *list* of users and he can simply check the user that should approve the contract. once the end-user is done, he can close the window (button to commit) and return to the form for submit.

thanks for any pointers
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You will need to use JavaScript for this. If you don't have a pretty good handle on JavaScript already, you will need to get your hands on some good reference materials and spend some time learning it. Here is the basic process you would follow:
  • Open the window using the window.open(...) function. The URI you specify can refer to a JSP that will create the list of approvers with checkboxes
  • Put Javascript in the JSP attached to the new window such that When the user presses the "OK" button, it uses the "opener" attribute of the window to get a reference to the opening window document. Once you have this reference, you can iterate through the list of checked approvers in the child window and add hidden fields to the parent document that correspond to the approvers selected
  • Have the JavaScript tied to the "OK" button close the window with the window.close() function.
  • When the parent window is submitted, the created hidden fields will be submitted along with it. Make sure you have properties in your ActionForm to handle the approvers


  • Merrill
    Consultant, Sima Solutions
    Peter Primrose
    Ranch Hand

    Joined: Sep 10, 2004
    Posts: 755
    oh...I thought I could avoid the javascript :-(

    here's another possibility: what if I can open a new window with a list of all users, and the end-user can choose from the list the approvers. when he clicks OK I can place all the list he requested on the HttpSession and than retrieve it after the end-user clicked submit on the main form?

    the only problem I'm not sure of is what happens when the user clicks OK on the approver's list - how to close the window from the Action?

    I'd also appreciate if you have any reference (URLS) for your first javaScript solution.

    thank you Merrill
    Merrill Higginson
    Ranch Hand

    Joined: Feb 15, 2005
    Posts: 4864
    Putting the approvers in the session will work also. However, when you're working with popup windows, there's no way to avoid Javascript entirely. You must use it to open and close the window.

    If you're going to submit a form from the popup window, here's what I'd recommend: Create a small HTML file named closeWindow.htm that contains the following:

    *Note onnload should be onload

    Then have your Action class forward to "closeWindow.htm" to close the window after it has put the data in the session. The reason I recommend doing it this way is that when I've tried to close the window in the JSP that contains the form, I've run into strange problems with the fact that sometimes the window closes before the form gets properly submitted and the data is lost.

    In answer to your question about reference material, I've found that one of the best sites is Microsoft Development Network (MSDN). Obviously it assumes you're using Microsoft Internet Explorer, so you have to be careful to cross-reference it with other sources to make sure what it tells you is valid for other browsers. Here is the link:

    http://msdn2.microsoft.com/en-us/library/aa342502.aspx
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: how to create a 'diaolg'? bttn that open a new-win ->when closed - rtrn to main form