Re: JSTL Tags Vs. JavaBeans
Jeff, Here's an example of how I did what you were looking for in regards to building a select menu based on data pulled from a database. There is a page before this one in which the user selects which project they're looking to edit and it's passed on to the page containing the code below. The first query is used to get the values to build the entire select menu. The second query gets the technology that associated with the chosen project ID. The nested 'forEach' that I did also allows for if there is more than one technology associated with the project they chose and generates multiple drop-down menus if there are. As it builds the select menu it compares the current value to the chosen one. If it is, the 'selected' attribute is inserted. If you have any questions about it, feel free to ask! Keith sql:query var=tech_menu SELECT technology_id, technology_name FROM technology_types ORDER BY technology_name /sql:query sql:query var=chosen_tech SELECT technology_id FROM technology_registry WHERE project_id = ? sql:param value=${param.project_id} / ORDER BY technology_name /sql:query c:forEach items=${chosen_tech.rows} var=current_tech select name=technology_id c:forEach items=${tech_menu.rows} var=tech_row option value=${tech_row.technology_id} c:if test=${current_tech.technology_id == tech_row.technology_id} selected /c:if ${fn:escapeXml(tech_row.technology_name)} /option /c:forEach %-- end forEach for tech_row --% /select br /c:forEach %-- end forEach for chosen_tech --% -- Original Message --- From: Jeff Brewer [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sun, 11 Apr 2004 18:17:05 -0400 Subject: Re: JSTL Tags Vs. JavaBeans Sure. Here's a piece of what I'm in the middle of trying to update right now. It started out using the jsp:useBean tag followed by the jsp:getProperty tags. One of the limitations (probably due to my own ignorance) I ran into was some way of writing the options for a select tag that would select the appropriate option corresponding to the value found in the database. Note in the source select tag below, I simply wrote a function in my bean that would iterate all of the options in the bean while building a string containing all the necessary HTML code. Contrast that with link_type options that I built this afternoon where I'm using JSTL to iterate a collection of very simple objects. Here all of the HTML code is on the JSP page. I guess what I mean by using beans vs. using JSTL tags has to do more with how I get the data onto the page. For example, on this page I can write the sourceUrl value by either... c:out value=${dumfriesArticle.sourceUrl} / ...or... jsp:getProperty name=dumfriesArticle property=sourceUrl / Right now I'm inclined to be consistent (as consistently as I can) and since I like using the c:forEach approach to building the option elements for my select tag I'm inclined to use the c: set of tags throughout and just get rid of the jsp: tags. Anyway, that's enough rambling for one post. Thanks for responding! Here's my code sample... %@ page import = com.dumfries.utilities.*, java.util.ArrayList, java.util.Iterator, java.util.Collections% %@ taglib prefix=c uri=/WEB-INF/lib/c.tld % jsp:useBean id=dumfriesArticle scope=request type=com.dumfries.utilities.ArticleForm / form name=article_detail method=post action=updatearticle table border=1 width=100% cellspacing=0 cellpadding=4 tr td align=rightp class=fID:/td tdjsp:getProperty name=dumfriesArticle property=articleKey //td input type=hidden name=article_id value=jsp:getProperty name=dumfriesArticle property=articleKey / /tr tr td align=rightp class=fTitle:/td tdtextarea cols=75 name=title rows=3 wrap=softjsp:getProperty name=dumfriesArticle property=title //textarea/td /tr tr td align=rightp class=fSubtitle:/td tdtextarea name=subtitle cols=75 rows=3 wrap=softjsp:getProperty name=dumfriesArticle property=subtitle //textarea/td /tr tr td align=rightp class=fByline:/td tdtextarea name=byline cols=75 rows=3 wrap=softjsp:getProperty name=dumfriesArticle property=byline //textarea/td /tr tr td align=rightp class=fArticle Date:/td tdinput type=text name=article_date size=10 value=jsp:getProperty name=dumfriesArticle property=articleDate //td /tr tr td align=rightp class=fsource:/td td jsp:getProperty name=dumfriesArticle property=articleSource / /td /tr tr td align=rightp class=fBody:/td
Prohibited content
Can someone please do something about the Taglibs mailing list responding with Prohibited Content? Nearly every message I send bounces this back to me (even when it doesn't contain JSP code), and a number of others keep resending their messages, thinking they never get through because of the same thing. All we're sending is plain text messages with no attachments. Keith - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Tomcat 5.0 - x:forEach returns incorrect result?
Mark, When you do a x:forEach, the forEach action sets the current context node to whatever the select attribute is pointing to. So, when you point back to $test/teamname[1] in the x:out action, x:out can't find that under the context that forEach is currently pointing to. Try this instead: x:forEach select=$teams/doc/teamname varStatus=status %-- Same two lines as above but inside x:forEach, they return nothing --% Team c:out value=${status.count}/: x:out select=. / br / /x:forEach The only difference is that it will only give you the list once, since it only iterates over the two teams once. Notice how I had to add a counting mechanism as well, for which I used varStatus and the count function. Remember also to add %@ taglib prefix=c uri=http://java.sun.com/jsp/jstl/core; % at the top of your page to use the core library. Hope this helps! Chris -Original Message- From: Mark Brunkhart [mailto:[EMAIL PROTECTED] Sent: Saturday, April 10, 2004 8:16 PM To: [EMAIL PROTECTED] Subject: Tomcat 5.0 - x:forEach returns incorrect result? Hi all, Unless we've botched our installation of Tomcat 5.0 somehow or don't understand some nuance of JSTL 1.2 (both reasonable possibilities), I believe we've hit a major bug with x:forEach. Inside of a x:forEach, node-set variables defined outside the forEach appear to change their values (see test case below). I did not see this reported in the bug database. Could someone test this sample on a working Tomcat 5.0 and confirm our suspicion that this is a bug? Thanks, Mark --- Test case --- [EMAIL PROTECTED] contentType=text/html; charset=UTF-8 session=true % %@ taglib prefix=x uri=http://java.sun.com/jsp/jstl/xml; % html body x:parse var=teams doc teamnameRedskins/teamname teamnameCowboys/teamname /doc /x:parse x:set var=test select=$teams/doc/* / Team 1: x:out select=$test/teamname[1] /br / Team 2: x:out select=$test/teamname[2] /br / x:forEach select=$teams/doc/teamname %-- Same two lines as above but inside x:forEach, they return nothing --% Team 1: x:out select=$test/teamname[1] / br / Team 2: x:out select=$test/teamname[2] / br / /x:forEach /body /html -- Test results --- Team 1: Redskins Team 2: Cowboys Team 1: Team 2: Team 1: Team 2: --- Should be --- Team 1: Redskins Team 2: Cowboys Team 1: Redskins Team 2: Cowboys Team 1: Redskins Team 2: Cowboys - 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]
RE: isLast() method of LoopTagStatus class
try loop_status.last instead of loop_status.isLast(). EL will translate it as per javabeans specification -Original Message- From: Keith [mailto:[EMAIL PROTECTED] Sent: 12 April 2004 18:41 To: Taglibs Subject: isLast() method of LoopTagStatus class I'm trying to output a comma delimited list based on a varying list of statuses that will be input from a select menu in a form. I was trying to figure out how to avoid putting a comma after the last value, and it seemed like testing with the isLast() method of the LoopTagStatus class would be a good thing to use. I'm not quite sure how to go about using it, though. Reading about it, it looks like the 'varStatus' attribute of the c:forEach tag creates a variable to hold a LoopTagStatus object. My code below was how I assumed I would then be able to access the isLast() method: %@ page contentType=text/html; charset=iso-8859-1 language=java % %@ taglib prefix=c uri=http://java.sun.com/jsp/jstl/core; % %@ taglib prefix=sql uri=http://java.sun.com/jsp/jstl/sql; % c:forEach items=${paramValues.status} var=status_row varStatus=loop_status '${status_row.status_name}' c:if test=${!(loop_status.isLast())}, /c:if /c:forEach But when I do this, I get the following error back: org.apache.jasper.JasperException: /report_status_data.jsp(20,3) The function isLast must be used with a prefix when a default namespace is not specified Here's an example of the kind of output I'm trying to generate. The list has a possibility of being shorter or longer than this: 'In-Progress', 'Closed', 'Terminated', 'Withdrawn' Thanks in advance! Keith - 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]
RE: isLast() method of LoopTagStatus class
Perfect! Thanks! Where would I have looked to find that info? I'm still really new to Beans and raw Java code. Main reason why I'm going with JSTL right now. I had tried looking in the Java Docs, but I really didn't know where to begin. Keith -- Original Message --- From: Felix Velasco [EMAIL PROTECTED] To: 'Tag Libraries Users List' [EMAIL PROTECTED] Sent: Mon, 12 Apr 2004 18:41:51 +0200 Subject: RE: isLast() method of LoopTagStatus class try loop_status.last instead of loop_status.isLast(). EL will translate it as per javabeans specification -Original Message- From: Keith [mailto:[EMAIL PROTECTED] Sent: 12 April 2004 18:41 To: Taglibs Subject: isLast() method of LoopTagStatus class I'm trying to output a comma delimited list based on a varying list of statuses that will be input from a select menu in a form. I was trying to figure out how to avoid putting a comma after the last value, and it seemed like testing with the isLast() method of the LoopTagStatus class would be a good thing to use. I'm not quite sure how to go about using it, though. Reading about it, it looks like the 'varStatus' attribute of the c:forEach tag creates a variable to hold a LoopTagStatus object. My code below was how I assumed I would then be able to access the isLast() method: %@ page contentType=text/html; charset=iso-8859-1 language=java % %@ taglib prefix=c uri=http://java.sun.com/jsp/jstl/core; % %@ taglib prefix=sql uri=http://java.sun.com/jsp/jstl/sql; % c:forEach items=${paramValues.status} var=status_row varStatus=loop_status '${status_row.status_name}' c:if test=${!(loop_status.isLast())}, /c:if /c:forEach But when I do this, I get the following error back: org.apache.jasper.JasperException: /report_status_data.jsp(20,3) The function isLast must be used with a prefix when a default namespace is not specified Here's an example of the kind of output I'm trying to generate. The list has a possibility of being shorter or longer than this: 'In-Progress', 'Closed', 'Terminated', 'Withdrawn' Thanks in advance! Keith - 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] --- End of Original Message --- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: isLast() method of LoopTagStatus class
this is a very basic application of the JavaBeans spec, and I don't really think you should read it to use in jstl. You just need to know that any class with non-static methods starting with get, set or is (this last one only for booleans) is a JavaBean to you. Then, to call this method, remove the prefix and lowercase the first letter after it. Unless there are more than one uppercase letters, so: getId() -- .id getID() -- .ID In most EL tutorials you'll find this better explained, I'd start with Shawn Bayern's book, JSTL in Action, probably the best there is for JSTL. -Original Message- From: Keith [mailto:[EMAIL PROTECTED] Sent: 12 April 2004 18:57 To: Tag Libraries Users List Subject: RE: isLast() method of LoopTagStatus class Perfect! Thanks! Where would I have looked to find that info? I'm still really new to Beans and raw Java code. Main reason why I'm going with JSTL right now. I had tried looking in the Java Docs, but I really didn't know where to begin. Keith -- Original Message --- From: Felix Velasco [EMAIL PROTECTED] To: 'Tag Libraries Users List' [EMAIL PROTECTED] Sent: Mon, 12 Apr 2004 18:41:51 +0200 Subject: RE: isLast() method of LoopTagStatus class try loop_status.last instead of loop_status.isLast(). EL will translate it as per javabeans specification -Original Message- From: Keith [mailto:[EMAIL PROTECTED] Sent: 12 April 2004 18:41 To: Taglibs Subject: isLast() method of LoopTagStatus class I'm trying to output a comma delimited list based on a varying list of statuses that will be input from a select menu in a form. I was trying to figure out how to avoid putting a comma after the last value, and it seemed like testing with the isLast() method of the LoopTagStatus class would be a good thing to use. I'm not quite sure how to go about using it, though. Reading about it, it looks like the 'varStatus' attribute of the c:forEach tag creates a variable to hold a LoopTagStatus object. My code below was how I assumed I would then be able to access the isLast() method: %@ page contentType=text/html; charset=iso-8859-1 language=java % %@ taglib prefix=c uri=http://java.sun.com/jsp/jstl/core; % %@ taglib prefix=sql uri=http://java.sun.com/jsp/jstl/sql; % c:forEach items=${paramValues.status} var=status_row varStatus=loop_status '${status_row.status_name}' c:if test=${!(loop_status.isLast())}, /c:if /c:forEach But when I do this, I get the following error back: org.apache.jasper.JasperException: /report_status_data.jsp(20,3) The function isLast must be used with a prefix when a default namespace is not specified Here's an example of the kind of output I'm trying to generate. The list has a possibility of being shorter or longer than this: 'In-Progress', 'Closed', 'Terminated', 'Withdrawn' Thanks in advance! Keith - 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] --- End of Original Message --- - 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]
RE: isLast() method of LoopTagStatus class
I have Hans Bergsten's JSP book from O'Reilly. I'm only about 1/3 of the way through it so far, so I may not have gotten to a point where he explained that yet. Thanks for the reference and Bean explination, though! Helps a lot. Keith -- Original Message --- From: Felix Velasco [EMAIL PROTECTED] To: 'Tag Libraries Users List' [EMAIL PROTECTED] Sent: Mon, 12 Apr 2004 19:02:54 +0200 Subject: RE: isLast() method of LoopTagStatus class this is a very basic application of the JavaBeans spec, and I don't really think you should read it to use in jstl. You just need to know that any class with non-static methods starting with get, set or is (this last one only for booleans) is a JavaBean to you. Then, to call this method, remove the prefix and lowercase the first letter after it. Unless there are more than one uppercase letters, so: getId() -- .id getID() -- .ID In most EL tutorials you'll find this better explained, I'd start with Shawn Bayern's book, JSTL in Action, probably the best there is for JSTL. -Original Message- From: Keith [mailto:[EMAIL PROTECTED] Sent: 12 April 2004 18:57 To: Tag Libraries Users List Subject: RE: isLast() method of LoopTagStatus class Perfect! Thanks! Where would I have looked to find that info? I'm still really new to Beans and raw Java code. Main reason why I'm going with JSTL right now. I had tried looking in the Java Docs, but I really didn't know where to begin. Keith -- Original Message --- From: Felix Velasco [EMAIL PROTECTED] To: 'Tag Libraries Users List' [EMAIL PROTECTED] Sent: Mon, 12 Apr 2004 18:41:51 +0200 Subject: RE: isLast() method of LoopTagStatus class try loop_status.last instead of loop_status.isLast(). EL will translate it as per javabeans specification -Original Message- From: Keith [mailto:[EMAIL PROTECTED] Sent: 12 April 2004 18:41 To: Taglibs Subject: isLast() method of LoopTagStatus class I'm trying to output a comma delimited list based on a varying list of statuses that will be input from a select menu in a form. I was trying to figure out how to avoid putting a comma after the last value, and it seemed like testing with the isLast() method of the LoopTagStatus class would be a good thing to use. I'm not quite sure how to go about using it, though. Reading about it, it looks like the 'varStatus' attribute of the c:forEach tag creates a variable to hold a LoopTagStatus object. My code below was how I assumed I would then be able to access the isLast() method: %@ page contentType=text/html; charset=iso-8859-1 language=java % %@ taglib prefix=c uri=http://java.sun.com/jsp/jstl/core; % %@ taglib prefix=sql uri=http://java.sun.com/jsp/jstl/sql; % c:forEach items=${paramValues.status} var=status_row varStatus=loop_status '${status_row.status_name}' c:if test=${!(loop_status.isLast())}, /c:if /c:forEach But when I do this, I get the following error back: org.apache.jasper.JasperException: /report_status_data.jsp(20,3) The function isLast must be used with a prefix when a default namespace is not specified Here's an example of the kind of output I'm trying to generate. The list has a possibility of being shorter or longer than this: 'In-Progress', 'Closed', 'Terminated', 'Withdrawn' Thanks in advance! Keith - 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] --- End of Original Message --- - 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] --- End of Original Message --- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]