Kemp Randy-W18971 wrote:
> This is probably a simple question, but I can't find the answer. I am developing
>some JSP forms mapping values to a CMP EJB bean and RDMS database. My boss wants to
>change some text fields in the JSP pages for adding and updating to radio buttons. I
>can easily set the value with code like this on initial adding:
>
> <tr>
> <td class="normaltext" width="122" height="32">
> <div align="center">
> <input type="radio" name="Course001" value="No">
> <span class="newslist">N</span>
> <input type="radio" name="Course001" value="Basic">
> <span class="newslist">B</span>
> <input type="radio" name="Course001" value="Advanced">
> <span class="newslist">A</span></div>
> </td>
>
> When I get to the update part, I am not sure how to set the radio button to a
>database value. Can someone share a code example in the TD element for setting the
>radio button with a value from a database or point me to a web site? I can't find
>any in my JSP books.
Well, here's how you'd do this with WebWork
(sourceforge.net/projects/webwork). First make a form JavaBean with the
field:
public class CourseForm
{
String course001 = "No";
public void setCourse001(String str)
{
course001 = str;
}
public String getCourse001()
{
return course001;
}
public Map getCourseTypes()
{
// You can of course put this in a separate
// JavaBean if you want to (recommended)
Map types = new HashMap();
types.put("No","No");
types.put("Basic","Basic");
types.put("Advanced","Advanced");
return types;
}
}
And in the JSP's form you'd do:
<webwork:include page="/template/standard/radiomap.jsp">
<webwork:param name="label" value="Course type:"/>
<webwork:param name="name" value="course001"/>
<webwork:param name="list" value="courseTypes"/>
<webwork:param name="key" value="key"/>
<webwork:param name="value" value="value"/>
</webwork:include>
--
Done. To customize this you can either change radiomap.jsp (which prints
out the radio button), or you can change a CSS stylesheet which is used
by the template JSP's (recommended).
WebWork also gives you per-field error messages that you can use. See
this example for more info:
Form JavaBean:
http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/webwork/src/main/webwork/test/FormTestForm.java?rev=1.2&content-type=text/x-cvsweb-markup&cvsroot=webwork
Validation of above form:
http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/webwork/src/main/webwork/test/FormTest.java?rev=1.3&content-type=text/x-cvsweb-markup&cvsroot=webwork
JSP used to view this form:
http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/webwork/src/resources/formtest.jsp?rev=1.6&content-type=text/x-cvsweb-markup&cvsroot=webwork
To run this example download the latest WebWork file release and deploy
webwork.war.
Hope this helps.
/Rickard
--
Rickard �berg
Email: [EMAIL PROTECTED]
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]