Click to See Complete Forum and Search --> : useBean setProperty


lakshman
05-04-2003, 08:20 PM
Hi everyone,

Q1. How do I set a value I received from an input field in an HTML form, into a useBean setMethod within my javascript function findCustomer()

Note : I am able to store a literal value.


Q2. How do I retrieve the useBean Object in my controller servlet.

eg

main.jsp
----------
<jsp:useBean id="srchCustomer" class="com.ap.SrchCustomer" scope="request" />
.
.
.
.
<script language="JavaScript">
function findCustomer()
{
alert("document.frmTab.srchName.value : " + document.frmTab.srchName.value);

<%srchCustomer.setSrchName(????????); %>
}

</script>
.
.
.
.
<input type="text" name="srchName" size="40" maxlength="50"/>
.
.
.


SrchCustomer.java
---------------------
package com.ap;

import java.io.*;

public class SrchCustomer implements Serializable
{
String name=null;

public SrchCustomer() {}
public void setSrchName(String cName) {name = cName;}
}



Thanks in advance.

khalidali63
05-04-2003, 09:07 PM
Originally posted by lakshman
.......... <%srchCustomer.setSrchName(????????); %>
}
.........

You can not do that,reason being Javascript runs on client side that is in the scope of a browser window,where as your jsp code runs on the webserver.
The only way to forward information from client ot serer is using HTTP Request object.
What you need to do is submit theinformation to the jsp page and in the jsp code get the info frm request object using
String value = request.getParameter("FromFieldName")
//once this is done then
srchCustomer.setSrchName(value);

for jsp questions though,best place will be
http://forum.java.sun.com/forum.jsp?forum=45

lakshman
05-04-2003, 10:15 PM
Hi khalid,

Thanks a million. You are champ.

So much to learn and so little time....!!!

khalidali63
05-04-2003, 11:46 PM
:D

You are welcome,
Glad to be of any help