Solved

Struts and pop up window

Posted on 2006-07-21
7
1,300 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
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.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
zip code lookup from address state list 4 82
Market Place not working in Eclipse Luna 2 118
by zero exception 10 52
Hiding Adsense on Mobile Devices 2 28
Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
Online promotion is consistently becoming more important for all types of businesses. From Facebook ads to search engines to YouTube videos, there are all sorts of channels that can effectively be used to promote a business or product. But how shoul…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

839 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