Wrox Programmer Forums
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2006, 11:45 AM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ibsidd Send a message via Yahoo to ibsidd
Default JSP & FRAMES

I have 2 vertically aligned frames. In my left frame I have a drop down listbox populated w/entries from a resultset of a query to a database. When the user selects an entry(option), the entry (parameter) needs to be passed to the right frame.
This is at run time and doesn't use any form or submit button.
What is the best way to do this being each frame should have a jsp page.

Any helpful advice?
Thanks!

Ibrahim Siddiqui
 
Old January 28th, 2006, 06:22 AM
Authorized User
 
Join Date: Jan 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to longjava
Default

What you need to do is using javascript from the left frame to notify the right frame each time a user selects a new item from the select object.

Here I wrote a template code of how to notify the right frame from the left frame when there is a rew item is selected. By the way, this code I wrote on-the-fly without testing it so please check the syntax since I might be making mistakes about the syntax.

//File: main.html
<html>
<head>
<script type='text/javascript'>
</script>
</head>
<frameset cols='30%,70%'>
   <frame src='left.jsp' name='left'>
   <frame src='right.jsp' name='right'>
</framset>
<html>

---------------------------------

//File: left.jsp
<html>
<head>
<script type='text/javascript'>
function notifyRightFrameWithNewItemSelected( value )
{
   window.top.frames['right'].updateNewItemSelected( value );
}

function itemSelected()
{
   var oSelect = document.getElementById( 'resultSet' );
   if ( oSelect != null )
   {
      var item = oSelect.options[oSelect.selectedIndex].value;
      notifyRightFrameWithNewItemSelected( item );
   }
}
</script>
</head>
<body>
   <%-- Assume your resultset is a List object containing a collection
        of Strings sending back from the server via request object --%>
   <%
      List resultSet = (List) request.getAttribute( "resultSet" );
   %>
   <select name='resultSet' id='resultSet' onselect='itemSelected()'>
      <%
         if ( resultSet != null && resultSet.size() > 0 )
         {
            for ( int i = 0; i < resultSet.size(); i++ )
        {
           String item = (String) resultSet.get( i );
      %>
               <option value='<%=item%>'><%=item%></option>
      <%
            }
     }
      %>
   </select>
</body>
</html>

---------------------------------

//File right.jsp
<html>
<head>
<script type='text/javascript'>
function updateNewItemSelected( newItem )
{
   document.myForm.resultSetItem.value = newItem;
}
</script>
</head>
<body>
<%-- display a selected item from the left frame in the textbox field --%>
<form name='myForm' id='myForm'>
   <input type='text' name='resultSetItem' value=''>
</form>
</body>
</html>






Similar Threads
Thread Thread Starter Forum Replies Last Post
jsp & tomcat aruna_k_2006 JSP Basics 1 March 23rd, 2007 07:16 AM
JSP & Proxy Issue mmcgough JSP Basics 0 March 29th, 2005 11:05 AM
input in html & output in jsp Befekadu Pro JSP 0 March 28th, 2005 10:28 AM
JSP & HTTP Server Request Jstmehr4u3 JSP Basics 0 March 2nd, 2004 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.