aspose file tools*
The moose likes Struts and the fly likes Problem with Struts and javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with Struts and javascript" Watch "Problem with Struts and javascript" New topic
Author

Problem with Struts and javascript

Anna Ferrari
Greenhorn

Joined: Aug 18, 2006
Posts: 14
Hi,
from my first jsp I call with javascript another jsp for select one item from a table,the second jsp update two attribute in the first one jsp. My problem is that :I desire to re-use the second jsp in many situations, but with my code i can't.

This is the first jsp :

.....

<tr>
<td>Articolo</td>
<td><html:text property="moaridDesc" /></td>
<td><html:hidden property="moarid" /></td>
<td><html:input type="button" name="choise"
onKlick="window.open('<thtml:rewrite page='/artgest.do?do=ricerca'/>', ' ', width=500,height=400, top=100, left=700');" value="Ricerca"></td>
</tr>
......

This is the second jsp :

.....

<SCRIPT language="Javascript">

function sendValue(arId, arcodi) {
window.opener.document.movimentoBeanForm.moarid.value=arId;
window.opener.document.movimentoBeanForm.moaridDesc.value=arcodi;window.close();
}

.....


<logic:interate name="articoloBeanForm" property="articoloDOL" id="articolo" >
<tr>
<td>
<a href='javascript nKlick=sendValue(<bean:write name="articolo" property="arId" />,
"<bean:write name="articolo" property="arcodi" /> ")'>
<bean:write name="articolo" property="arcodi" /> </a>
</td>
</tr>
.......

The application works well, but the code inside sendValue reports only to movimentoBeanForm.
Any idea for resolve the problem?
Thanks.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You could make this function more generic like this:


The additional parameters are:

  • form - the Name of the form
  • idInput - the input used for the ID
  • descInput - the Input used for the description


  • Merrill
    Consultant, Sima Solutions
    Anna Ferrari
    Greenhorn

    Joined: Aug 18, 2006
    Posts: 14
    Thank you Merrill Higginson for your answer, I take inspiration from you to resolve my problem and then i do like this:

    In the first jsp i create three session's attributes :

    <SCRIPT LANGUAGE="JavaScript">
    function ricercaArticolo(){
    <% session.setAttribute("bf", "movimentoBeanForm");
    session.setAttribute("f1", "moarid");
    session.setAttribute("f2", "moaridDesc");
    %>
    window.open('<html:rewrite page='/artgest.do?do=ricerca'/>',
    '','width=500,height=400,top=100,left=700');
    }
    </script


    And in the second I use those three session's attributes :

    <SCRIPT LANGUAGE="JavaScript">
    function sendValue(arId, arcodi){
    window.opener.document.<%= session.getAttribute("bf") %>.
    <%= session.getAttribute("f1") %>.value = arId;
    window.opener.document.<%= session.getAttribute("bf") %>.
    <%= session.getAttribute("f2") %>.value = arcodi;
    window.close();
    }
    </script>

    I think this is one step on, again thanks.Bye.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Problem with Struts and javascript