Write a custom tag - that's exactly what they are for,
Kevin Jones
DevelopMentor
www.develop.com
> -----Original Message-----
> From: A mailing list about Java Server Pages specification and
> reference [mailto:[EMAIL PROTECTED]]On Behalf Of Michal Belicek
> Sent: 06 September 2000 17:08
> To: [EMAIL PROTECTED]
> Subject: HTML tags in JSP function ???
>
>
> I need to put in jsp file many times a set of HTML tags which are
> differencing from each other with only one word. I thought about writing
> some JSP function and then call the function with the differencing word
> as parameter. I encountered some problems creating the function so I
> ended with messy
> <jsp:include page=
> <jsp:param name=
> but I still dream about some cute function.
>
> Example:
>
> <input type="radio" name="English" value="0" checked>
> <input type="radio" name="English" value="1">
> <input type="radio" name="English" value="2">
> <input type="radio" name="English" value="3">
>
> <input type="radio" name="Otherlanguage" value="0" checked>
> <input type="radio" name="Otherlanguage" value="1">
> <input type="radio" name="Otherlanguage" value="2">
> <input type="radio" name="Otherlanguage" value="3">
>
> I have a set of radioboxes, four for each language. Say I have about 100
> languages to display, so I would need about 400+ lines of code written
> by hand :-(
>
> My solution is:
>
> ---file1.jsp---
>
> <input type="radio" name="<%= request.getParameter("language")%>"
> value="0" checked>
> <input type="radio" name="<%= request.getParameter("language")%>"
> value="1">
> <input type="radio" name="<%= request.getParameter("language")%>"
> value="2">
> <input type="radio" name="<%= request.getParameter("language")%>"
> value="3">
>
> ---end of file1.jsp---
>
> --file2.jsp---
>
> <jsp:include page="file1.jsp" flush="true">
> <jsp:param name="language" value="English"/>
> </jsp:include>
> <jsp:include page="file1.jsp" flush="true">
> <jsp:param name="language" value="Otherlanguage"/>
> </jsp:include>
>
> ---end of file2.jsp---
>
> This is more convenient but still time consuming.
> I think some function like this would be better:
>
> <%!
> void langRadio(String language) {
> out.print("<input type=\"radio\" name=\"" + language + "\"
> value=\"0\" checked>");
> out.print("<input type=\"radio\" name=\"" + language + "\"
> value=\"1\">");
> out.print("<input type=\"radio\" name=\"" + language + "\"
> value=\"2\">");
> out.print("<input type=\"radio\" name=\"" + language + "\"
> value=\"3\">");
> }
> %>
>
> but this will not compile. I get:
> org.apache.jasper.JasperException: Unable to compile class for
> JSP/usr/local/jakarta-tomcat/work/localhost_8080%2Fdotaznik/_0002f
> dotaznik_0002ejspdotaznik_jsp_84.java:23:
> Undefined variable or class name: out
> out.print("");
>
> Comments, help and suggestions very welcomed. Thanx.
> --
> Michal Belicek
> mailto:[EMAIL PROTECTED]
>
> ==================================================================
> =========
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets