• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1552
  • Last Modified:

Struts and pop up window

I need some urgent help

need to open a pop up jsp in from a parent jsp page. The pop up jsp should include two radio buttons  - say delete all and delete this only. Then have a cancel and a delete button. I then need to pass the option value selected back to the parent page. In the parent page I will use the value of the option to send send in a form action for either deleteAll or delete.

I am new to struts and so I do not know what changes and where the changes need to be done. Can you please provide sample code for the pop up jsp and how it can be invoked from the parent jsp and additionally how can I then use that option to pass the necessary action to the Action class. What all changes will be required.

The parent jsp has a delete button to delete a record selected...when user clicks on this delete button on the parent page, the pop up window should provide delete options. When option selected close window (if possible) or click on cancel to close the window.

Please help!!!

thanks

0
c0nazaa
Asked:
c0nazaa
  • 4
  • 3
1 Solution
 
owenli27Commented:
Your pop-up JSP can directly send request to your action class to delete record(s), why you need to send the selected option value back to parent JSP?

Anyway, in your parent JSP,  delete button can trigger a javascript function like:
<input type="button" name="del_record" value="Delete" onClick="jsDelRecord(this.form)">

In your javascript, you can popup JSP by this example:
function jsDelRecord(formName)
{
    var theHref = "Popup.jsp?delRecordID="+formName.record1.value+'&deleteAll='+formName.deleteAll.value... ...
    view_window = window.open(theHref,'_blank','alwaysOnTop=yes, toolbar=0,menubar=0,scrollbars=1,resizable=1,location=0,directories=0,width=530,height=700',status=1);
    formName.submit();
    return true;
}

Then, in your Popup.jsp, put passed record info in hidden before user select radio button about delete all ot delete this one
0
 
c0nazaaAuthor Commented:
Thank you for your prompt response as well as for the suggestions provided...

can you please me do some revisions...

basically, i want to just pass the action values of "DeleteAll" or "DeleteThisOnly" to the action class...depending on what the user selects...

For Add...I have a drop down...if selected index is 0, i need to provide a pop up which will then pass form action values of "addAll" or "addThisOnly" to the action class...
Currently parent jsp triggers submitSpocList javascript function


Please can you help correct me...

Parent JSP
function submitSpocList() {
     alert("Selected SPOC value : "+document.forms[spocForm].selectedSpocList.value);
   
     if(document.forms[spocForm].selectedSpocList.value == 0 ){
           addSpocScreen();
     }
     else{
           document.forms["spocForm"].formAction.value = "SpocList";
           document.forms["spocForm"].submit();
     }
         
   }
 
   function addSpocScreen(){
        var url="<%=contextPath%>/SPOCInforMappingAction.do?formAction=openSpocAddOptionsScreen";
        document.forms["spocForm"].formAction.value = "openSpocAddOptionsScreen";
       
        if (typeof(popupWin) != "object"){
                      popupWin = window.open(url, "SpocAddOptionsScreen",
                                        "width=300,height=400,resizable=yes,scrollbars=yes,toolbar=no,location=no,status=no,menubar=no");
             }      
             else{
                      if (!popupWin.closed){
                  popupWin.location.href = url;
                     }
                     else{
                      popupWin = window.open(url, "SpocAddOptionsScreen", "width=300,height=400,scrollbars=yes,toolbar=no,location=no,status=no,menubar=no");
                     }
        }
   }
 
   function deleteSpocScreen(){
        
          var url="<%=contextPath%>/SPOCInforMappingAction.do?formAction=openSpocDeleteOptionsScreen";
        document.forms["spocForm"].formAction.value = "openSpocDeleteOptionsScreen";
       
        if (typeof(popupWin) != "object"){
                      popupWin = window.open(url, "spocDeleteOptionsScreen",
                                        "width=400,height=350,scrollbars=yes,toolbar=no,location=no,status=no,menubar=no");
             }      
             else{
                      if (!popupWin.closed){
                  popupWin.location.href = url;
                     }
                     else{
                      popupWin = window.open(url, "spocDeleteOptionsScreen",
                            "width=400,height=300,scrollbars=yes,toolbar=no,location=no,status=no,menubar=no");
                     }
        }
       
        //var val =document.forms["spocForm"].delOptions.value;
        //alert("spoc delete option is "+val);
          
       
  }


POP UP JSP ( same for add and delete)
<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%
   String contextPath = request.getContextPath();
   String textClass = "etextField";
   
   String actionPath = "SPOCInforMappingAction.do" ;
   String formBeanName = "SPOCInforFormBean";
   
%>
<html>
<head>
  <link rel="STYLESHEET" type="text/css" href="<%=contextPath%>/ewi/ecpd/jsp/ewiusage.css">
  <script language="JavaScript" type="text/JavaScript">
 
        function submitDeleteAll() {
            alert("delete all called for spoc");
            alert(document.forms["spocForm"].selectedSpocList.value);
            
            document.forms["spocForm"].spocUpdateOption.value=5;
           document.forms["spocForm"].formAction.value = "DeleteAll";
        document.forms["spocForm"].submit();
        window.close();
    }
     
    function submitDeleteThisOnly() {
        alert("delete this only called for spoc");
        alert(document.forms["spocForm"].selectedSpocList.value);
            
        document.forms["spocForm"].formAction.value = "Delete";
        document.forms["spocForm"].submit();
        window.close();
    }
 
    function check() {
               opener.document.forms["spocForm"].formAction.value = "refresh";
             opener.document.forms["spocForm"].submit();
             window.close();
     }
 
    function cancel(){
          window.close();
    }
   
 </script>
</head>
<!--  <body onload = "check()" > -->
<body>

<html:form action="<%=actionPath%>" styleId="spocForm">
<html:hidden property="formAction" />      
 <table width="100%" bgcolor="#6699cc" border="0" cellpadding="0" cellspacing="0">
  <tr>
   <td class="section-title" width="100%">SPOC Delete Options</td>
  </tr>
  <tr>
       <td align="left">
          <html:button property="deleteAllButton" styleClass="screenbutton" value="addAll" onclick ="submitDeleteAll()"/>
       </td>
    <td align="left">
          <html:button property="deleteThisButton" styleClass="screenbutton" value="save" onclick ="submitDeleteThisOnly()"/>
    </td>
  </tr>
  <tr>
    <td align="center">
            <html:button property="cancelButton" styleClass="screenbutton" value="Cancel" onclick="cancel()"/>
       </td>
 </tr>
</table>
</html:form>  
0
 
c0nazaaAuthor Commented:
I managed to find something before your response came in and so posted the contents of that earlier to this...I am not sure how to go about putting in your changes...yours look simple...
the new pop up jsp should i have it included in the struts-config.xml...as well?

Again..thank you so much..please assist me when you get the time. Thanks
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
owenli27Commented:
You already have a project structure and don't have to change it by following my idea.

You are sending request to formAction in your Javascitpt function(not to request Popup jsp). I guess that you have to config your new pop up JSP in struts-config.xml and let action class forward request back to your Popup JSP.  Does your Javascipt function work fine to popup new window? (I am home and have no J2ee IDE now)




 
0
 
c0nazaaAuthor Commented:
Yes the javascript opens the new pop up window but it shows a pop up page as well as a pop up window. When I close it, it closes the browser window. The pop window also does not look good in terms of the buttons being scattered everywhere.......

For the add, is it possible to submit two actions within one javascript function??
For instance

      function submitAddAll() {
            alert("add all called for spoc");
            
            if ( !checkString(document.forms["spocForm"].firstName, "First Name", false))
         return;
        if ( !checkString(document.forms["spocForm"].lastName, "Last Name", false))    
         return;
        if ( !checkUSPhone(document.forms["spocForm"].phoneNumber,  false))
         return ;
        if ( !checkUSPhone(document.forms["spocForm"].mobileNumber,  true))
         return ;
        if ( !checkUSPhone(document.forms["spocForm"].faxNumber,  true))
         return ;
         
        alert(document.forms["spocForm"].selectedSpocList.value);
            
            document.forms["spocForm"].formAction.value = "SpocList";
            document.forms["spocForm"].submit();
                    document.forms["spocForm"].spocUpdateOption.value=4;
           document.forms["spocForm"].formAction.value = "addAll";
                    document.forms["spocForm"].submit();
                    window.close();
    }

the window.close does not seem to be doing the right thing....

Any suggestions??

Thanks
0
 
owenli27Commented:
If you submit twice to an action, only your final submit is guaranteed and first submit may randomly work. You should avoid submit twice in one javascript function.   your window.close(); should be fine but some browsers may popup warning message to user before close window.  

If you still cannot make your program work. you may try to call Popup JSP directly from your parent JSP Javascript function instead of sending request to action.
0
 
c0nazaaAuthor Commented:
ok I will try your suggestion. Thank you very much for taking the time to address my question.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now