From: "Murray Collingwood" <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <user@struts.apache.org>
To: "Struts Users Mailing List" <user@struts.apache.org>
Subject: Re: how many Form beans
Date: Fri, 28 Oct 2005 23:32:09 +1000
Hi
When I first read the subject line I thought the question was, "How many
form beans
does it take to change a light bulb?" Maybe this is a question for the
more advanced
Struts user - I'm not sure of the answer to that question. Any ideas Wendy
/ Laurie?
I like to keep things simple....I think 'simple' is my favourite word. You
really need two
separate objects.
// Your first object packages a single currency value, including the type,
currency and
// amount. I have guessed at the types you might use.
public class CurrencyValue extends ActionForm {
private int type;
private String currency;
private float amount;
CurrencyValue() {
super();
}
// include normal getters and setters here
}
// The second class is then a simple collection of the above objects
public class CurrencyValueList extends ActionForm {
private List entries;
CurrencyValueList() {
super();
}
public List getEntries() {
return entries;
}
public void setEntries(List entries) {
this.entries = entries;
}
}
In your action class you then populate the form beans above and push them
into the
request scope (or session scope). When you push them into the request
scope you
provide an identifier name as in "cvList" in the following example:
request.setAttribute("cvList", currencyValueList);
In your JSP you can then iterate over them using:
<logic:iterate name="cvList" id="cv" type="CurrencyValue">
<jsp:getProperty name="cv" property="type"/>
<jsp:getProperty name="cv" property="currency"/>
<jsp:getProperty name="cv" property="amount"/>
</logic:iterate>
I hope that helps makes things clearer.
Kind regards
mc
On 28 Oct 2005 at 9:12, fea jabi wrote:
>
> According to what you suggested
>
> I created the below in the action
> String row1[][] = {{"type1","currency1","amount1"},
> {"type2","currency2","amount2"},
> {"type3","currency3","amount3"},
> {"type4","currency4","amount4"},
> {"type5","currency5","amount5"},
> };
>
> and set it's value to the form bean (i.e Form1) attribute which is
>
> private String[][] rows;
>
> public void setrows(String[][] rows) {
> this.rows = rows;
> }
> public String[][] getrows() {
> return rows;
> }
>
>
> not really sure how to iterate now in jsp? how do I populated the data
now?
> under the columns type, currency, amount??
>
> <logic:iterate id="rowid" property="rows">
> <tr>
>
> </tr>
> </logic:iterate>
>
>
> Thanks.
>
>
> >From: Laurie Harper <[EMAIL PROTECTED]>
> >Reply-To: "Struts Users Mailing List" <user@struts.apache.org>
> >To: user@struts.apache.org
> >Subject: Re: how many Form beans
> >Date: Thu, 27 Oct 2005 22:33:06 -0400
> >
> >fea jabi wrote:
> >>thankyou for your responses.
> >>
> >>for my Jsp I created a formbean and for ---- Form1
> >>with attributes
> >>name
> >>row[]
> >>
> >>table row in the jsp created another formbean.--- Form2
> >>with attributes
> >>type
> >>currency
> >>amount
> >>
> >>In the action I created dummy data
> >>Form2[] ----- row[] and set it to the form1 attribute
> >
> >I'm not sure I understand what you're doing here. Are you saying that
Form1
> >and Form2 are ActionForm subclasses, and that 'row' in Form1 is an
array of
> >Form2 instances? And that the JSP is rendering a single form, part of
which
> >is shown in a table? In that case, Form2 doesn't have to be a form bean
> >(ActionForm instance), it can be any arbitrary java bean -- or you
could
> >have Form1 declare three arrays named type[], currency[] and amount[].
> >
> >There's lots of options here, depending on exactly what you're trying
to
> >achieve. That said, if I understand what you have then it should work.
> >
> >>Now I am not sure how this row[] values to be displayed using struts
in
> >>the jsp. i mean how to loop thru this to get values.
> >
> >To loop through a colllection of values, you would use the
> ><logic:iteratate> tag from Struts [1] or, if you have it available, the
> ><c:forEach> tag from JSTL.
> >
> >Maybe you could post your code, JSP and struts-config.xml so we can see
> >more clearly what you're doing.
> >
> >HTH,
> >
> >L.
> >
> >[1]
>
>http://struts.apache.org/struts-taglib/tagreference-struts-logic.html#iterate
> >
> >>
> >>I would appreciate your help.
> >>
> >>can I do this?? or is there an easier way to display data in table?
> >>
> >>thanks.
> >>
> >>
> >>
> >>
> >>
> >>
> >>>From: "Martin Gainty" <[EMAIL PROTECTED]>
> >>>Reply-To: "Martin Gainty" <[EMAIL PROTECTED]>
> >>>To: "Struts Users Mailing List" <user@struts.apache.org>
> >>>Subject: Re: how many Form beans
> >>>Date: Thu, 27 Oct 2005 17:16:09 -0400
> >>>
> >>>A couple of gotchas concerning TagLibs
> >>>
> >>>what version JSP container ?
> >>>if its 2.0 then consider JSTL 1.1.x tags
> >>>
> >>>On the other hand the struts html tag library outstrips anything
> >>>available from JSTL
> >>>But if you want performance steer clear Struts logic: tags as they
rank
> >>>slowest of all available Logic Taglibs
> >>>
> >>>If you are concerned about being tied into a TagLib that doesnt
> >>>accomplish everything you want to do go with scriptlets
> >>>and wait for JSF Tag Library
> >>>
> >>>Good Luck,
> >>>Martin-
> >>>----- Original Message ----- From: "Laurie Harper"
<[EMAIL PROTECTED]>
> >>>To: <user@struts.apache.org>
> >>>Sent: Thursday, October 27, 2005 3:51 PM
> >>>Subject: Re: how many Form beans
> >>>
> >>>
> >>>>fea jabi wrote:
> >>>>
> >>>>>I am new to web development and struts too.
> >>>>>
> >>>>>I am trying to create a jsp which has
> >>>>>
> >>>>>a text field for display only for Name
> >>>>>
> >>>>>and a Table below it with couple of rows and columns in it.
> >>>>>
> >>>>>
> >>>>>how many form beans do I have to create?
> >>>>>
> >>>>>Do I have to create one for the jsp and one for the table alone?
> >>>>>
> >>>>>do I have to use nested tag? not really sure. if so how do I have
to
> >>>>>use this in jsp?
> >>>>
> >>>>
> >>>>It's really up to you to a large extent. You can have a single form
bean
> >>>>for an entire application if you want. One for each page that has a
form
> >>>>on it is probably typical though.
> >>>>
> >>>>The User Guide section on developing view components [1] may help
you
> >>>>get a better overall understanding of what your options are.
> >>>>
> >>>>I'm not sure when you say 'nested tags' if you're referring to the
> >>>>'nested' tag library, or if you just mean having tags nested inside
> >>>>other tags. Assuming the former, no, you don't necessarily need to
use
> >>>>them, though they may make some things easier. I'd suggest getting
to
> >>>>grips with the basics first and then looking at the 'nested' taglib
> >>>>again later, when you'll be better able to understand if what it
offers
> >>>>applies to what you're doing.
> >>>>
> >>>>L.
> >>>>
> >>>>[1]
http://struts.apache.org/struts-core/userGuide/building_view.html
> >>>>
> >>>>
>
>>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>>>For additional commands, e-mail: [EMAIL PROTECTED]
> >>>>
> >>>>
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>>For additional commands, e-mail: [EMAIL PROTECTED]
> >>>
> >>
> >>_________________________________________________________________
> >>Is your PC infected? Get a FREE online computer virus scan from
McAfee®
> >>Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
> _________________________________________________________________
> Dont just search. Find. Check out the new MSN Search!
> http://search.msn.click-url.com/go/onm00200636ave/direct/01/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.362 / Virus Database: 267.12.5/150 - Release Date:
27/10/2005
>
FOCUS Computing - web design
Mob: 0415 24 26 24
[EMAIL PROTECTED]
http://www.focus-computing.com.au
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.12.5/150 - Release Date: 27/10/2005
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]