You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bueno Carlos M <Ca...@irs.gov> on 2003/03/07 21:22:43 UTC

RE: [Q] Presentation of confirmation information that is meaningf ul to user?

Perl/PHP/TCL weenies who take good string parsing support for granted
usually stuff the value field like so:

     <option value="501|||Accounting">Accounting</option>

You can do this in Java with the nifty org.apache.regexp package (or
javax.regexp if you like crappy Sun JSR implementations). It works but it
ain't pretty and it ain't bulletproof.

Javascript weenies take the display value and put it in a hidden field:

    <input type="hidden" name="deptName" />
    <select name="dept"
onchange="this.form.deptName.value=this.selected.text;">
    <option value="501">Accounting</option>

Works ok, but is somewhat fragile on the browser end.

Newbies of any language go back to the database or hard-code the mappings
because you just don't learn unless you paint yourself into a corner a few
times.

If you want to be really clever, you cache it in memory. Since you are
getting the mappings from the database anyway to build your form, stick it
in a hashtable/hashmap in session scope. Once you have that working, figure
out how to share that cache across sessions so you don't bloat your memory
space. Then count the number of lines you wrote and finally realize why the
Perl/Javascript weenies do it the way they do. :) 

KISS.

-- los

-----Original Message-----
From: Rick Reumann [mailto:maillist@reumann.net]
Sent: Friday, March 07, 2003 11:08 AM
To: Struts Users Mailing List
Subject: [Q] Presentation of confirmation information that is meaningful
to user?


I'm wondering how many of you handles a typical situation that comes up
for me:

Say you are working on an application that requires the user to enter in
Employee information so that it could be inserted into a database.

You have a select options field created which displays the list of
departments and the user needs to select the appropriate one for the
Employee. Since the database cares about the department ID and not the
department name it makes sense to have the value for your options be
this "ID" and then you just display the department names from your
colleciton so that a typical option viewed as source would look like:

<option value="501">Accounting</option>

Obviously I then have a form bean which will hold this department ID
when the form is submitted. 

The problem I run into though is that I often want to display back
confirmation information that might include the actual department name
the user selected (displaying the id would mean nothing to the user).

How do you guys accomplish this?

There are several ways I can accomplish it but none of them that I'm
aware of are very pretty. 

-- 
Rick Reumann

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org

Re: [Q] Presentation of confirmation information that is meaningf ul to user?

Posted by Rick Reumann <ma...@reumann.net>.
On Fri, 7 Mar 2003 15:22:43 -0500 
Bueno Carlos  M <Ca...@irs.gov> wrote:
 
> Javascript weenies take the display value and put it in a hidden
> field:
> 
>     <input type="hidden" name="deptName" />
>     <select name="dept"
> onchange="this.form.deptName.value=this.selected.text;">
>     <option value="501">Accounting</option>

Thanks Carlos and Joe,
I tend to usually use this javascript solution or place maps in
application scope and do a look up in my action and add it to the
formBean there. Appreciated your feedback.  Thanks.

 
-- 
Rick Reumann

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org