Solved

Struts and pop up window

Posted on 2006-07-21
7
1,327 Views
Last Modified: 2013-11-28
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
Comment
Question by:c0nazaa
  • 4
  • 3
7 Comments
 
LVL 9

Expert Comment

by:owenli27
ID: 17158777
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
 

Author Comment

by:c0nazaa
ID: 17161064
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
 

Author Comment

by:c0nazaa
ID: 17161070
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!

 
LVL 9

Expert Comment

by:owenli27
ID: 17161818
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
 

Author Comment

by:c0nazaa
ID: 17163077
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
 
LVL 9

Accepted Solution

by:
owenli27 earned 500 total points
ID: 17163418
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
 

Author Comment

by:c0nazaa
ID: 17163497
ok I will try your suggestion. Thank you very much for taking the time to address my question.
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For many of us, the  holiday season kindles the natural urge to give back to our friends, family members and communities. While it's easy for friends to notice the impact of such deeds, understanding the contributions of businesses and enterprises i…
In this blog, I will share you some basic tips for content marketing and to rank your website on Google.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question