Re: Introductory Struts Article / Tutorial / Reference page

2001-04-14 Thread Ted Husted

I'm unsure if you should mention using more than one controller at 

 http://www.jspinsider.com/tutorials/jsp/struts/struts.html 

Typically, there is just one ActionServlet (controller), but several
Actions.

The text also seems to imply that Struts provides a model object, which
may confuse people. 

Struts provides a simple, and entirely optional, connection pool for
JDBC applications, but does not otherwise address the model. (BYOM -
Bring Your Own Model.)

The diagram also seems to say the Stuts Tag libraries connect with the
model. They connect with JavaBeans that may have been created elsewhere,
and based on model, and may later update the model, but the Struts tags
do not address the model directly. (Though other custom tags, like the
Struts-compatible Taglib JDBC tags, may.)

Something that isn't clear to many people at first is that the
struts-config file is used to create a mappings database, which is the
heart of the controller. The config file is not read directly while
Struts is running -- the mappings are stored in memory. In many ways,
the mappings ~are~ the controller. Once you understand the mappings, you
understand Struts. You might want to list the struts-config file sooner,
next to the web.xml file. As you say, the secret to Struts is the
configuration files, and struts-config is the key configuration file.
(Very little works without it!)

At  http://www.jspinsider.com/tutorials/jsp/struts/gettingstarted.html


there's a formatting glitch at the bottom of the page. 

Struts not capitalized in many places throughout, you might want to
sweep each page for struts-Struts.

Thanks for listing my resource page -- much appreciated!

casey kochmer wrote:
 
 Hi everyone,
 
 I just wrote up a struts article / tutorial / lesson.
 
 the link is
 
 http://www.jspinsider.com/tutorials/jsp/struts/strutsintro.html
 
 This is introductory level materials, and we will add more advance lessons
 later. The article won't go up offically till the weekend
 (We are in the final stages of editoral review for grammer and such)
 But I wanted to prerelease it so I could get technical feedback from the
 struts community before the final version goes up.
 
 Thanks!
 Casey Kochmer
 [EMAIL PROTECTED]
 _
 Get your FREE download of MSN Explorer at http://explorer.msn.com



Re: Bean-applet support?

2001-04-14 Thread Jim Crossley

"Craig R. McClanahan" wrote:
 
 You might ask your staff to look inside the "commercial" pacakges they are
 using - they would probably be fascinated to find that the web server
 inside IBM's WebSphere is actually Apache (for example).

Not to get too off-topic, but IBM didn't stop with Apache. 
Interestingly, they use Allaire's JRun as WebSphere's servlet container.



Re: logic:iterate questions

2001-04-14 Thread Jim Crossley

See below.

"Craig R. McClanahan" wrote:
 
  2) I have a bean that has a collection of Phone objects, accessible via
  its getPhones() method.  Shouldn't I be able to return EITHER a Phone[]
  or a java.util.Collection?  The following element works fine when a
  Collection is returned, but I get an error ("No getter method for
  property phones of bean myForm") when a Phone[] is returned.
 
  logic:iterate id="phone" name="myForm" property="phones" 
  tr
td
  bean:write name="phone" property="type" /
/td
td
  html:text name="phone" property="number" /
/td
  /tr
  /logic:iterate
 
  Thanks in advance.
 
 
 Can you post the actual getPhones() method of your form bean in the case
 where this fails?

It's pretty typical, in that it returns an actual Phone[] member:

  public Phone[] getPhones() { return this.phones; }

However, the "setter" was a little different:

  public void setPhones (Collection c) { ... }

I came to the conclusion that Struts wasn't too happy dealing one type
for the getter's return and another for the setter's parameter.  I
wasn't able to confirm that by looking at the source, though.



Template tags

2001-04-14 Thread Olivier Houyoux

Hi,

I'm using the template library to create a dynamic template for index pages
that share the same format (see below). One of the pages (menu.jsp) that
compose the template has a form which validation is handled by two
components : the associated ActionForm object for the simple validation and
the associated Action object for specific business logic validation.
If a validation error occurs, the request is redirected to the calling page
automatically by the ActionForm (I suppose) or manually by my Action object
(return new RedirectingActionForward("/index.jsp")).
Unfortunately, a part of the index page content is then lost : only the page
with the form (menu.jsp) is correctly displayed, the other parts
(header.jsp, body.jsp and footer.jsp) seem to be ignored.

What's wrong ? Is that a context relative path problem ? Any idea on how to
fix it ?


Here is my 'index.jsp' page :

%@ taglib uri="/WEB-INF/tlds/struts-template.tld" prefix="template" %

template:insert template="/template.jsp" 
template:put name="header" content="/header.jsp" /
template:put name="menu" content="/menu.jsp" /
template:put name="body" content="/body.jsp" /
template:put name="footer" content="/footer.jsp" /
/template:insert


Regards,

Olivier.




Serialize object to form.. class mismatch?

2001-04-14 Thread Michael Mok

Hi

Young Wayne posted an previous in regards to getting version mismatch error
when serializing class.

I encountered similar problem when serializing my object as well. The errors
are

java.io.InvalidClassException: java.lang.Integer; Local class not
compatible: stream classdesc serialVersionUID=1360826667802527544 local
class serialVersionUID=1360826667806852920
at java.io.ObjectStreamClass.validateLocalClass(ObjectStreamClass.java:523)
at java.io.ObjectStreamClass.setClass(ObjectStreamClass.java:567) at
java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:936)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:366) at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:236) at
java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1186) at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:386) at
java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:2262) at
java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:519) at
java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1411) at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:386) at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:236) at
org.teatimej.timesheet.dao.Project.setSerializeOrg(Project.java:355)
at java.lang.reflect.Method.invoke(Native Method)
at
org.apache.struts.util.PropertyUtils.setSimpleProperty(PropertyUtils.java:82
5)
at
org.apache.struts.util.PropertyUtils.copyProperties(PropertyUtils.java:209)
at org.teatimej.timesheet.form.ProjectForm.setProject(ProjectForm.java:59)


setSerializeOrg code is

   byte buf[] = sOrg.getBytes();
   ByteArrayInputStream bais =
   new ByteArrayInputStream(buf);
   ObjectInputStream ois = new ObjectInputStream(bais);
   this._organisation = (Organisation)ois.readObject();
   ois.close();


getSerializeOrg code is

ByteArrayOutputStream baos =
new ByteArrayOutputStream(100);
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(this._organisation);
byte buf[] = baos.toByteArray();
oos.close();
return new String(buf);



Any idea or workaround?

TIA


Michael Mok

www.webappcabaret.com/teatimej




Pre populating a Form Bean

2001-04-14 Thread Tewathia, Atul
Title: Pre populating a Form Bean






I want to pre-populate a formBean in this scenario.


Jsp1 -- Jsp2


When I process the data of jsp1 using form1 in the perform method how do I set the form2 attributes .. so that the jsp2 is displayed with preloaded data.

Can any body guide in this ??





Re: advantages of Struts

2001-04-14 Thread Ted Husted

I think the best discussion of "Why we need Struts" is summed up in
Jason Hunter's. article regarding the difficulties with JSP Model 1
applications. 

 http://www.servlets.com/soapbox/problems-jsp.html 

What all this boils down to is that Struts gives you a place to stand. 

Without a controller, a Web application is a breathless stream of views. 

With a controller, a Web application is a series of requests and
responses, as HTTP intended. The views request and an action responds
with another view. Ideally, your views become scriplet-free "JavaBean
Pages", that could be easily edited with a visual Java 2 Web editor (at
least as soon as we get one!). 

A MVC application like Struts does force you to be more organized, and
does compels you to define objects that in a model 1 application may
only be implied. But the objects are still there and so is the work.
It's just whether you want to spend your time defining JavaBeans or
cutting and pasting code snippets between JSPs. 

The next big step will be to integrate rowsets into Struts. If we can
use rowsets where we use JavaBeans now, we can drop a layer of
abstraction, and actually gain both flexibility and functionality. Many
actions then become very simple adapters that just retrieve a rowset and
pass it to the request. The Struts forms could then read and set the
fields on the rowset, and the rowset could be used to update the model
directly when it was returned. No additional hand-offs. The best thing
here being that rowsets can work with any tabular data, not just JDBC.

 http://developer.java.sun.com/developer/earlyAccess/crs/ 

Sadly, the current Sun implementations require transactions to update a
JDBC table, and the (default) MySQL tables still don't support
transactions. I tried turning transactions off   
(setTransactionIsolation(TRANSACTION_NONE), but it just laughed and
tossed the exception anyway. So right now, I'm using rowsets for
retrievals, and conventional connections for insertions. In between, I
dump the rowsets into JavaBeans, but hope to skip that step soon and
send the rowsets directly to the JSPs.

Iraklis Kourtidis wrote:
 
 Hi fellow Struts users,
 
 I wanted to start a small discussion on something very general: what Struts
 gets you over embedding scriptlets in your JSPs (i.e., Struts vs. no
 Struts). I know, it's Friday, so we should all be going home... anyway, here
 goes it:
 
 Given my (limited) experience in developing a small application, what I
 personally see as the biggest advantage is the following:
 
 * Action classes can run the code that would normally get executed as a
 scriptlet in a JSP (or as glorified function calls through tags).
 * The Action classes place a bunch of beans on the request/session.
 * The JSP then runs and displays the information stored in these beans,
 possibly using logic:iterate.
 
 One disadvantage that I see is that all the communication from the action
 classes to the JSPs happens through beans placed on the request/session. A
 JSP-only solution would display the information directly without making
 beans out of it (and without the necessary java bean classes to represent
 information that gets sent to a JSP in the form of a bean.)
 
 At any rate, I like the fact that Struts makes it possible to completely
 remove any code from the JSP files, which makes it easier for the design
 staff to modify layout etc. etc. I know, you don't need Struts to do this,
 but in reality if you look at most JSPs out there, you'll find a ton of
 scriptlet code in the JSP (I've been heard of threads being started inside a
 JSP...) So Struts makes it easier for me to separate the presentation from
 the code behind it.
 
 I am curious about how (and why) the rest of you gain from Struts.



The Struts User's Guide 1.0 translated in German language

2001-04-14 Thread Hartmut Bernecker

Einleitung in Struts 1.0
(German translation of "Struts User's Guide")

URL:

http://habweb.de/struts/

cheers
Hartmut Bernecker
//
Hartmut Bernecker
Heinrich-Rorbeck-Weg 30
73614 Schorndorf
Tel. 0 71 81 / 25 75 39
Fax. 0 71 81 / 25 75 41
[EMAIL PROTECTED]
\\




Re: The Struts User's Guide 1.0 translated in German language

2001-04-14 Thread Ted Husted

Ach du lieber! 

I suppose translation is also the sincerest form of flattery!

(If you subscribe to Struts-Dev, you can watch for any CVS updates to
the documentation ;-)

Hartmut Bernecker wrote:
 
 Einleitung in Struts 1.0
 (German translation of "Struts User's Guide")
 
 URL:
 
 http://habweb.de/struts/



RE: Action Forms And Model objects

2001-04-14 Thread Niall Pemberton

JavaScript just makes the client side more interactive (which is good) but
it doesn't reduce the need to do stuff server side since for safety you
still need to repeat all the validation on the server side.

 -Original Message-
 From: Rajan Gupta [mailto:[EMAIL PROTECTED]]
 Sent: 14 April 2001 04:50
 To: [EMAIL PROTECTED]
 Subject: RE: Action Forms And Model objects


 ON 2nd thoughts, could one not achieve the results you are expecting using
 client side JavaScript?
 --- Rajan Gupta [EMAIL PROTECTED] wrote:
  Niall,
  I guess your formula does reduce coding for ActionsForms which require
  simple validation  do not need to access the model for any type of
  validation, but I think you will still have to write a class for every
  form where you will create your validation rules. This does not
  eliminate
  the total number of classes vs. the total number of classes required by
  Struts. Please correct me if I did not get this right.
 
  Maybe you could use XML-Schema to define every rules for every form.
  Rules
  can be associated based upon a form name which is handed over to
  ActionServlet using a request parameter. The GenericActionForm can load
  the XMLSchema for the form  validate the the form input. Regardless, it
  is good idea  definetly worth pursuing with a purpose of reducing the
  number of classes required in the application implementation.
 
  Rajan Gupta
 
  --- Niall Pemberton [EMAIL PROTECTED] wrote:
   I'm still developing/debugging it at the moment so its fairly
   rudimentary at
   the moment. I'm still considering how I could devlop it at the moment
  -
   possibly your XML idea.
  
   I have extended Action and done some stuff in the perform method to
  cast
   the
   form and manage a connection and then call a processForm() method.
  Also
   it
   handles control with standard success  failure forwards but I'm
  looking
   at
   developing that as well - probably creating a transport object rather
   than
   just returning a String message key.
  
   A processForm() method validating input looks something like this:
  
 protected String processForm(HttpServletRequest request,
  HttpServletResponse response,
  GenericActionForm form,
  Connection connection) throws Exception
  {
  
   // Validate the form
   form.setRule("empl_id", true, form.INT);// required Integer
   form.setRule("empl_name", true);// required String
   form.setRule("empl_dob", true, form.DATE);  // required date
   form.setRule("empl_married", form.BOOLEAN); // optional Boolean
   if (form.validateProperties() != null) {
 return message;
   }
  
   // Store values from the form in GenericBean(s)
   GenericBean bean = form.createBean();
  
   // Process Business Logic
   return message = new
   LogicBuildProgram().createBuildProgram(connection,
   bean);
 }
  
-Original Message-
From: Rajan Gupta [mailto:[EMAIL PROTECTED]]
Sent: 13 April 2001 13:32
To: [EMAIL PROTECTED]
Subject: RE: Action Forms And Model objects
   
   
How do you store or manage your validation rules since your
GenericActionForm could be validating fields types of forms?
--- Niall Pemberton [EMAIL PROTECTED] wrote:
  Niall-
  To understand it a little better, does it mean that you do not
   allow
  ActionServlet to call the validate() method on your
   GenericActionForm
  since u do your validation in Action instead? Or I missed
   something!

 Yes.

  Also, do you store your validation rules in some type of a XML
   file or
  similar?

 No.

  Further, I would imagine that your Action itself checks with the
   model
 for
  any incorrect data in the form if it needs to?

 Yes.

  I guess u still derive GenericActionForm from ActionForm

 Yes.

  -Rajan
  --- Niall Pemberton [EMAIL PROTECTED] wrote:
   Normally you extend ActionForm and implement getters/setters
  for
 each
   property
 e.g.public String getCustName()
 public void setCustName(String name)
  
   I have a GenericActionForm which has some standard
   getters/setters
 e.g.public String getString(String property)
 public void setString(String property, String value)
  
   GenericActionForm stores these property/value pairs in
  internal
 arrays.
   I
   have customised ActionServlet to populate these and also
   customised
 some
   of
   the html tags to use the generic getter method if the form
  is
   an
   instance
   of my GenericActionForm.
  
   I don't really know what you mean by "dynamic" validation of
 properties.
   When processing a GenericActionForm in the Action you can set
  up
 rules
   for
   each of the 

RE: Action Forms And Model objects

2001-04-14 Thread Niall Pemberton

No, I don't agree with you.

My model is unchanged, containing validation rules, whether I use my
approach or standard Struts stuff.

I wouldn't have any validation rules in ActionForms if a could help it
except for the fact that, initially you need to store input as Strings so
that you can re-display what they user keyed in in the event of an error.

Using GenericActionForm and GenericBean I get rid of all the ActionForms and
"data" beans I had previously and can concentrate on the view (JSP's) and
model. For me it was alot less classes.

Thanks for your interest.

Niall
 -Original Message-
 From: Rajan Gupta [mailto:[EMAIL PROTECTED]]
 Sent: 14 April 2001 01:46
 To: [EMAIL PROTECTED]
 Subject: RE: Action Forms And Model objects


 Niall,
 I guess your formula does reduce coding for ActionsForms which require
 simple validation  do not need to access the model for any type of
 validation, but I think you will still have to write a class for every
 form where you will create your validation rules. This does not eliminate
 the total number of classes vs. the total number of classes required by
 Struts. Please correct me if I did not get this right.

 Maybe you could use XML-Schema to define every rules for every form. Rules
 can be associated based upon a form name which is handed over to
 ActionServlet using a request parameter. The GenericActionForm can load
 the XMLSchema for the form  validate the the form input. Regardless, it
 is good idea  definetly worth pursuing with a purpose of reducing the
 number of classes required in the application implementation.

 Rajan Gupta

 --- Niall Pemberton [EMAIL PROTECTED] wrote:
  I'm still developing/debugging it at the moment so its fairly
  rudimentary at
  the moment. I'm still considering how I could devlop it at the moment -
  possibly your XML idea.
 
  I have extended Action and done some stuff in the perform method to cast
  the
  form and manage a connection and then call a processForm() method. Also
  it
  handles control with standard success  failure forwards but I'm looking
  at
  developing that as well - probably creating a transport object rather
  than
  just returning a String message key.
 
  A processForm() method validating input looks something like this:
 
protected String processForm(HttpServletRequest request,
 HttpServletResponse response,
 GenericActionForm form,
 Connection connection) throws Exception {
 
  // Validate the form
  form.setRule("empl_id", true, form.INT);// required Integer
  form.setRule("empl_name", true);// required String
  form.setRule("empl_dob", true, form.DATE);  // required date
  form.setRule("empl_married", form.BOOLEAN); // optional Boolean
  if (form.validateProperties() != null) {
return message;
  }
 
  // Store values from the form in GenericBean(s)
  GenericBean bean = form.createBean();
 
  // Process Business Logic
  return message = new
  LogicBuildProgram().createBuildProgram(connection,
  bean);
}
 
   -Original Message-
   From: Rajan Gupta [mailto:[EMAIL PROTECTED]]
   Sent: 13 April 2001 13:32
   To: [EMAIL PROTECTED]
   Subject: RE: Action Forms And Model objects
  
  
   How do you store or manage your validation rules since your
   GenericActionForm could be validating fields types of forms?
   --- Niall Pemberton [EMAIL PROTECTED] wrote:
 Niall-
 To understand it a little better, does it mean that you do not
  allow
 ActionServlet to call the validate() method on your
  GenericActionForm
 since u do your validation in Action instead? Or I missed
  something!
   
Yes.
   
 Also, do you store your validation rules in some type of a XML
  file or
 similar?
   
No.
   
 Further, I would imagine that your Action itself checks with the
  model
for
 any incorrect data in the form if it needs to?
   
Yes.
   
 I guess u still derive GenericActionForm from ActionForm
   
Yes.
   
 -Rajan
 --- Niall Pemberton [EMAIL PROTECTED] wrote:
  Normally you extend ActionForm and implement getters/setters for
each
  property
  e.g.public String getCustName()
  public void setCustName(String name)
 
  I have a GenericActionForm which has some standard
  getters/setters
  e.g.public String getString(String property)
  public void setString(String property, String value)
 
  GenericActionForm stores these property/value pairs in internal
arrays.
  I
  have customised ActionServlet to populate these and also
  customised
some
  of
  the html tags to use the generic getter method if the form is
  an
  instance
  of my GenericActionForm.
 
  I don't really know what you mean by "dynamic" validation of
properties.
  When processing a 

Re: select option

2001-04-14 Thread Tharwat Abdul-Malik

I'm a newbie to struts. In fact I just downloaded it yesterday (Friday) and
thought I'd get involved. I built a very simple application last night. But
I think the struts tags already selects the correct item. I use something
like the following to display the items in a list.

html:select property="state"
html:options collection="stateList"  property="code"
labelProperty="description"/
/html:select

// Code Bean -- Basically encapsulates a name/value pair.
public class TypeCodeBean
{
protected String code = null;
protected String description = null;

public TypeCodeBean(String code, String description)
{
this.code = code;
this.description = description;
}

public String getCode()
{
return (code);
}

public String getDescription()
{
return (description);
}
}

// TypeCode List -- Extends the FastArrayList (faster for reads).
public class StateList extends org.apache.struts.util.FastArrayList
{
public StateList()
{
add(new TypeCodeBean("GA", "Georgia"));// Good to have
this read from a database.
add(new TypeCodeBean("FL", "Florida"));
}
}

I use a tag that encapsulates all of the code for creating the list and
stuffing it into the request object. So at the top of my jsp I would have
something like the following:
app:typecode id="stateList" /

Which would instantiate the StateList object and insert in the request. It
does something like the following:
if ("stateList".equals(id))
{
StateList stateList = new StateList();// Build list
request.setAttribute("stateList", stateList);// Stuff in request
}

You could just a well put the code in your jsp as a scriptlet...

As mentioned I'm new to struts so this is basically a hack. Over the next
day or so, I will rework the code as follows:

1. Create a TypeCode servlet that's loaded at startup.
2. The TypeCode servlet will implement the singleton pattern, it will
instantiate all of the code lists needed by the application (state code,
country code, etc). And store them in a Hash.
3. Modify the TypeCodeTag to use the singleton to get a list from the Hash
and then store it in the request object. This will prevent having to
instantiate the code lists for each request.
4. Modify the TypeCode class to get it's data from a database. This will
prevent having to hard code the code values. Useful for list that change
(for instance a list of referral codes).

Your are welcome to have any of the code, if you want it. Just shoot me an
email. I hope this helps.

Take care,
Tharwat





- Original Message -
From: "Nanduri, Amarnath" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, April 13, 2001 1:37 PM
Subject: RE: select option


 i have figured it out. Thankyou. Another quick question.

 I am updating my profile.
 I have bean A which contains the state i am in. I have an other bean which
 has the list of all states . Call it Bean B

 When the user initially comes to this page i have to show the state as
 "Virginia" in a select list.
 The user can modify the state to say "alabama"
 When the user submits information i want the 'state' variable to be set to
 'alabama' instead of 'virginia'.


   Is this feasible ?  Will this work ?

html:select name="aBean" property="state" size="1" 
 html:options name="bBean" labelName="states"/
/html:select

  class A  //session scope bean
  {
   private  String  state  = "virginia" ;

   public String  getState()
   {
 return  state ;
   }

   public  void  setState(String value)
   {
 state  =  value  ;
   }

  }


   class B   // application scope bean
   {
 private  ArrayList  states  = new ArrayList() ;

 public B()
 {
   states.add("alabama");
   states.add("Missisippi");
   states.add("Tenesse");
   states.add("virginia" ) ;
   states.add("Vermount" ;

 }


 public  Iterator  getStates()
 {
return  states.iterator() ;
 }

   }





 -Original Message-
 From: Nanduri, Amarnath [mailto:[EMAIL PROTECTED]]
 Sent: Friday, April 13, 2001 1:22 PM
 To: '[EMAIL PROTECTED]'
 Subject: select option



 Hi all,

   How do i implement the SELECT option using struts. I want to be able
to
 show a drop-down list from which the user can select what he/she wants.
The
 struts-test war file comes with a html:select example. this example
shows
 the whole list instead of in a drop down list. I need a drop down list.
any
 suggestions are appreciated. Thanks.

 cheers,
 Amar..





RE: select option

2001-04-14 Thread Nanduri, Amarnath

Hello Tharwat,

 Thank you very much for your help.

cheers,
Amar..

-Original Message-
From: Tharwat Abdul-Malik [mailto:[EMAIL PROTECTED]]
Sent: Saturday, April 14, 2001 3:19 PM
To: [EMAIL PROTECTED]
Subject: Re: select option


I'm a newbie to struts. In fact I just downloaded it yesterday (Friday) and
thought I'd get involved. I built a very simple application last night. But
I think the struts tags already selects the correct item. I use something
like the following to display the items in a list.

html:select property="state"
html:options collection="stateList"  property="code"
labelProperty="description"/
/html:select

// Code Bean -- Basically encapsulates a name/value pair.
public class TypeCodeBean
{
protected String code = null;
protected String description = null;

public TypeCodeBean(String code, String description)
{
this.code = code;
this.description = description;
}

public String getCode()
{
return (code);
}

public String getDescription()
{
return (description);
}
}

// TypeCode List -- Extends the FastArrayList (faster for reads).
public class StateList extends org.apache.struts.util.FastArrayList
{
public StateList()
{
add(new TypeCodeBean("GA", "Georgia"));// Good to have
this read from a database.
add(new TypeCodeBean("FL", "Florida"));
}
}

I use a tag that encapsulates all of the code for creating the list and
stuffing it into the request object. So at the top of my jsp I would have
something like the following:
app:typecode id="stateList" /

Which would instantiate the StateList object and insert in the request. It
does something like the following:
if ("stateList".equals(id))
{
StateList stateList = new StateList();// Build list
request.setAttribute("stateList", stateList);// Stuff in request
}

You could just a well put the code in your jsp as a scriptlet...

As mentioned I'm new to struts so this is basically a hack. Over the next
day or so, I will rework the code as follows:

1. Create a TypeCode servlet that's loaded at startup.
2. The TypeCode servlet will implement the singleton pattern, it will
instantiate all of the code lists needed by the application (state code,
country code, etc). And store them in a Hash.
3. Modify the TypeCodeTag to use the singleton to get a list from the Hash
and then store it in the request object. This will prevent having to
instantiate the code lists for each request.
4. Modify the TypeCode class to get it's data from a database. This will
prevent having to hard code the code values. Useful for list that change
(for instance a list of referral codes).

Your are welcome to have any of the code, if you want it. Just shoot me an
email. I hope this helps.

Take care,
Tharwat





- Original Message -
From: "Nanduri, Amarnath" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, April 13, 2001 1:37 PM
Subject: RE: select option


 i have figured it out. Thankyou. Another quick question.

 I am updating my profile.
 I have bean A which contains the state i am in. I have an other bean which
 has the list of all states . Call it Bean B

 When the user initially comes to this page i have to show the state as
 "Virginia" in a select list.
 The user can modify the state to say "alabama"
 When the user submits information i want the 'state' variable to be set to
 'alabama' instead of 'virginia'.


   Is this feasible ?  Will this work ?

html:select name="aBean" property="state" size="1" 
 html:options name="bBean" labelName="states"/
/html:select

  class A  //session scope bean
  {
   private  String  state  = "virginia" ;

   public String  getState()
   {
 return  state ;
   }

   public  void  setState(String value)
   {
 state  =  value  ;
   }

  }


   class B   // application scope bean
   {
 private  ArrayList  states  = new ArrayList() ;

 public B()
 {
   states.add("alabama");
   states.add("Missisippi");
   states.add("Tenesse");
   states.add("virginia" ) ;
   states.add("Vermount" ;

 }


 public  Iterator  getStates()
 {
return  states.iterator() ;
 }

   }





 -Original Message-
 From: Nanduri, Amarnath [mailto:[EMAIL PROTECTED]]
 Sent: Friday, April 13, 2001 1:22 PM
 To: '[EMAIL PROTECTED]'
 Subject: select option



 Hi all,

   How do i implement the SELECT option using struts. I want to be able
to
 show a drop-down list from which the user can select what he/she wants.
The
 struts-test war file comes with a html:select example. this example
shows
 the whole list instead of in a drop down list. I need a drop down list.
any
 suggestions are appreciated. Thanks.

 cheers,
 Amar..




Re: Pre populating a Form Bean

2001-04-14 Thread Tharwat Abdul-Malik
Title: Pre populating a Form Bean



Assuming that jsp2 will use the same data in the 
formBean, just stuff it in the request object in the perform method. Then jsp2 
can use the bean.

  - Original Message - 
  From: 
  Tewathia, Atul 
  To: '[EMAIL PROTECTED]' 
  
  Sent: Saturday, April 14, 2001 12:16 
  PM
  Subject: Pre populating a Form Bean
  
  I want to pre-populate a formBean in this 
  scenario. 
  Jsp1 -- Jsp2 
  When I process the data of jsp1 using form1 in the 
  perform method how do I set the form2 attributes .. so that the jsp2 is 
  displayed with preloaded data.
  Can any body guide in this ?? 



Re: Pre populating a Form Bean

2001-04-14 Thread Rajan Gupta

I think u should be able to Populate it in the Action of JSP1.
--- "Tewathia, Atul" [EMAIL PROTECTED] wrote:
 
 I want to pre-populate a formBean in this scenario.
 
 Jsp1 -- Jsp2
 
 When I process the data of jsp1 using form1 in the perform method how do
 I
 set the form2 attributes .. so that the jsp2 is displayed with preloaded
 data.
 
 Can any body guide in this ??
 


__
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/



RE: Pre populating a Form Bean

2001-04-14 Thread Tewathia, Atul
Title: Pre populating a Form Bean



Jsp1 
and jsp2 use different forms and different data.

  -Original Message-From: Tharwat Abdul-Malik 
  [mailto:[EMAIL PROTECTED]]Sent: Sunday, April 15, 2001 1:06 
  AMTo: [EMAIL PROTECTED]Subject: Re: Pre 
  populating a Form Bean
  Assuming that jsp2 will use the same data in the 
  formBean, just stuff it in the request object in the perform method. Then jsp2 
  can use the bean.
  
- Original Message - 
From: 
Tewathia, Atul 
To: '[EMAIL PROTECTED]' 

Sent: Saturday, April 14, 2001 12:16 
PM
Subject: Pre populating a Form 
Bean

I want to pre-populate a formBean in this 
scenario. 
Jsp1 -- Jsp2 
When I process the data of jsp1 using form1 in 
the perform method how do I set the form2 attributes .. so that the jsp2 is 
displayed with preloaded data.
Can any body guide in this ?? 
  


RE: Pre populating a Form Bean

2001-04-14 Thread Tewathia, Atul
Title: RE: Pre populating a Form Bean





It can't be done in action of jsp1 because there is no reference to the form of jsp2.


-Original Message-
From: Rajan Gupta [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 15, 2001 6:53 AM
To: [EMAIL PROTECTED]
Subject: Re: Pre populating a Form Bean



I think u should be able to Populate it in the Action of JSP1.
--- Tewathia, Atul [EMAIL PROTECTED] wrote:
 
 I want to pre-populate a formBean in this scenario.
 
 Jsp1 -- Jsp2
 
 When I process the data of jsp1 using form1 in the perform method how do
 I
 set the form2 attributes .. so that the jsp2 is displayed with preloaded
 data.
 
 Can any body guide in this ??
 



__
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/





Re: Pre populating a Form Bean

2001-04-14 Thread Tharwat Abdul-Malik
Title: RE: Pre populating a Form Bean



Does jsp1 forward to jsp2? If so, populate the bean 
in the perform method, stuff it in the request, the jsp2 can find it 
there.

  - Original Message - 
  From: 
  Tewathia, Atul 
  To: [EMAIL PROTECTED] 
  
  Sent: Sunday, April 15, 2001 12:46 
  AM
  Subject: RE: Pre populating a Form 
  Bean
  
  It can't be done in action of jsp1 because there is no 
  reference to the form of jsp2. 
  -Original Message- From: Rajan 
  Gupta [mailto:[EMAIL PROTECTED]] 
  Sent: Sunday, April 15, 2001 6:53 AM To: [EMAIL PROTECTED] 
  Subject: Re: Pre populating a Form Bean 
  I think u should be able to Populate it in the Action of 
  JSP1. --- "Tewathia, Atul" 
  [EMAIL PROTECTED] wrote:  
   I want to pre-populate a formBean in this 
  scenario.   Jsp1 
  -- Jsp2   When I 
  process the data of jsp1 using form1 in the perform method how do 
   I  set the form2 attributes 
  .. so that the jsp2 is displayed with preloaded  
  data.   Can any body 
  guide in this ??  
  __ 
  Do You Yahoo!? Get email at your own 
  domain with Yahoo! Mail. http://personal.mail.yahoo.com/