Updating Radio Button.

I need help.....

I have two radio button approved (A) and pending (P). This radio button receives value from database and also updates database. So that lets say initially field was marked as approved in Database. Now when I open form it should show me radio button checked as approved, but I want it to change to pending, so I clicked on pending and press submit at this point it should update radio button value in database as pending. Now when I open form again, I should see pending checked in radio button and not Approved. How do I acheive this goal? I am new to this field and trying to get some help from you experts.

Thank you very very very much in advance.... Please email me at ashlu4ever@msn.com.

[728 byte] By [akshay19a] at [2007-9-19]
# 1

Put the radio buttons in a ButtonGroup. You can determine if it is pending from the result of the call to your database. If the results show that it is pending, then ust the setSelected method on the button to make it selected. Since the radio buttons are in the button group, the Approved button will not be able to be set to selected if the pending is selected and vice versa... Small example below which is nowhere near complete but may convey the idea.

ButtonGroup approvedGroup = new ButtonGroup();

JRadioButton approvedRadioButton = new JRadioButton("Approved");

JRadioButton pendingRadioButton = new JRadioButton("Pending");

approvedGroup.add(approvedRadioButton);

approvedGroup.add(pendingRadioButton);

... Determine if item is pending from ResultSet of Database call....

if ( resultset shows pending is true) {

pendingRadioButton.setSelected(true);

}

Hope this helps

FB

fbeatty1a at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 2

Try this:

If u r using taglibs then try the following code or without taglibs too, it will work using separate connection and prepared statements. The example which i am giving is using tablibs

use the following code to retrieve database values;

<sql: connection -->

</sql:connection>

declare two variable

<%! String p1 = "";

String p2 = ""; %>

<sql:statement id ->

<sql:query> select statement -- with condition so that it will retrieve only one row</sql:query>

<html>

<body.

><form action = "process.jsp" method = "post">

<sql:resultSet id="rs">

-

--other html tags

-

for assigning radio button values which u retrieved for display, type the following code - assumption : 4 th column value of ur database contains radio button value

<% p1=rs.getString(4);

p2=rs.getString(4); %>

<% if(p.equals("approved") { p1="checked" } else

if(p.equals("pending") {p2="checked"};%>

to display the values retrieved and accept new values use input tags

<input type = "radio" name="rm" value="approved" ><%= p1 %>>

<input type = "radio" name="rm" value="pending" ><%= p2 %>>

this will show the retrieved values and also allow u to accept new values. when u submit, the radio button values will be passed on to process.jsp page where u can either call a bean to validate and update or using taglibs u can update with in process.jsp page it self

i think this will solve ur problem ,

madhu

madhum1a at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...