JSP-Java, object refrences

C

Colin Northway

I'm using jsp as a front end to a java application
In the application I have several instances of the same class.
I want to be able to present the user with an html menu of these objects and
have them choose a distinct instance.

How do I represent a particular instance of a class in my html form?

Simple eg:

I have instance A and B wich are both of the same class.

I have a jsp file create an html menu wich looks something like this:

<form action="this.jsp">
<select name="selectInstance">
<option>A</option>
<option>B</option>
</select>
</form>

I then want to proccess this form and discover wich one of the two instances
the user is refering to.

I would rather avoid giving each instance a unique ID. I'm dealing with a
large number of objects and the table of all objects would be large and hard
to maintain.

I'm open to creative suggestions.

Thanks

Colin Northway
 
E

Erwin Moller

Colin said:
I'm using jsp as a front end to a java application
In the application I have several instances of the same class.
I want to be able to present the user with an html menu of these objects
and have them choose a distinct instance.

How do I represent a particular instance of a class in my html form?

Simple eg:

I have instance A and B wich are both of the same class.

I have a jsp file create an html menu wich looks something like this:

<form action="this.jsp">
<select name="selectInstance">
<option>A</option>
<option>B</option>
</select>
</form>

I then want to proccess this form and discover wich one of the two
instances the user is refering to.

I would rather avoid giving each instance a unique ID. I'm dealing with a
large number of objects and the table of all objects would be large and
hard to maintain.

I'm open to creative suggestions.

Thanks

Colin Northway

Hi Colin,

Depending on where the instances belong logically (that is this specific
user or the whole application), I think I would store references to the
instances in session (user) or applicationcontect (application).
Give the instances a decent name and look them up using a hashtable stored
in applicationContext or session. Then pass the names to the options in
your select-elemant.

So that would end up in something like:
<form action="this.jsp">
<select name="selectInstance">
<option value="myKeyToInstanceA">A</option>
<option value="myKeyToInstanceB">B</option>
</select>
</form>

and eg for a user-specific Objects (stored in Session) in your servlet/jsp:
(with mySession)

Hashtable mySessionHash =
(Hashtable)mySession.getAtrribute("mySessionHash");

and then retrieve the Object based on the value of selectInstance.

Just my 2 cents.

Regards,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top