Hmmmm,
Bill, your code below works great, but it's too much code in an html
page for my liking. I've been really getting into the whole model 2
thing for my project and decided on another way to do the same thing -
which i use pretty much thru my entire site.
JSP page:
---------
<jsp:useBean id="item" scope="request" class="winston.ListBean"/>
...
...
<item:getProperty name="item" property="itemList" />
Bean:
-----
....
public String class getItemList(){
String htmlString;
// Do SQL stuff here
while( rs.next() ){
htmlString += "<option value=" + rs.getInt(1) +
">" + rs.getString(2) + "</option>";
}
// Obviously the above can be expensive beacause of the db hits.
// So I've set up beans that use hashtables/vectors resembling
// the db data and have an *application* scope. That allows me
// to leverage the speed of memory (this is not good if ram is
// low tho) and my objects only initalize once - when the app
// is started. I also have admin JSPs and servlets that can
// call a method in the bean and tell it to reload itself.
// This is important only if there's been a change to the
// underlying db data and the bean needs to reflect that.
return htmlString;
}
....
Now, obviously if you want to change any html code, it'll have to be
done in the bean vs. the html page. Which is and isn't okay. However,
I've taken into account that I may want to use these beans in other type
of front end access, so I've been building in 'switches' that will allow
me to specify whether I want the return info to be formatted in html or
text or something else. For me this works extremely well because I can
use the same bean across multiple presentation formats and I can
actually, based on the proper switch, return the info in a wide variety
of html tags - checkboxes, list, etc...
This might take a little of up front programming, but it saves a lot in
the long run. I'm always paranoid about reuse and design, so I try to
balance out performance with reuse and portability. For me the above
works very well.
Jason
Bill White wrote:
>
> Ok, let us see who is creative out there:
>
<SNIP>
> to hear how others of you have done this type of thing.
>
> Regards,
> bill
> [EMAIL PROTECTED]
>
> Here's the code:
>
> <jsp:useBean id="item" scope="request" class="winston.ListBean"/>
>
> <%!
> LinkedList linkList;
> SelectListItem selItem;
> int i;
> %>
>
> <%
> linkList=item.getNameList("Select PersonID, LastName, FirstName, MiddleName
> from People Order By LastName");
> %>
>
> <SELECT name="mylist">
> <%
> for(i=1;i<linkList.size();i++)
> {
> selItem=(SelectListItem)linkList.get(i);
> %>
> <option value=<%=selItem.getItemIndex() %>><%=selItem.getItemValue() %>
> <%
> }
> %>
> </SELECT>
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> FAQs on JSP can be found at:
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html