Maybe I wasn't clear. If the checkbox is checked in the addRecord.jsp
that means the value of isPermanent in the data table is true.  So when
that record is displayed in the editRecord.jsp the checkbox should be
checked.  I've got it working that way now by using the if/else in
editRecord.jsp but I wanted to avoid that if possible.

-----Original Message-----
From: Dave Newton [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, November 25, 2008 2:09 PM
To: Struts Users Mailing List
Subject: Re: Struts 1.2.9 and checkboxes

Why are you only using the checkbox tag in the "add record" page? Can't
you just set the ActionForm property and use it in the edit page also?

Dave

--- On Tue, 11/25/08, David Barron <[EMAIL PROTECTED]> wrote:
> I'm sure this has been asked before but I haven't had any luck finding

> the answer.  I'm having trouble getting the checkbox to work.
>  
> My web application uses a database and I have screens that add and 
> edit records.  One of the fields is a boolean called isPermanent.  So 
> my ActionForm has a boolean field called isPermanent.
>  
> public class DataSetForm extends ActionForm {
>     private boolean isPermanent;
>     public setIsPermanent(boolean b) {
>         isPermanent = b;
>     }
>     public getIsPermanent() {
>         return isPermanent;
>     }
> etc.
>  
> In my addRecord.jsp I've got my form setup and it includes this:
> <html:checkbox property="isPermanent"/>
>  
> And my Action has this:
> PreparedStatement stmt =
> connection.prepareStatement("insert into blah blah isPermanent=?"); 
> stmt.setBoolean(1, form.getIsPermanent()); stmt.execute();
>  
> All this works great.  My question is with the editRecord.jsp.  I'm 
> pulling the record out of the data based on the key field, but when I 
> display the checkbox how to if set it to checked based on the value in

> the data table?
>  
> Right now I'm doing something like this (greatly
> abbreviated)
>  
> <%
>     ResultSet rs = stmt.executeQuery("select etc");
>     if(rs.next()) {
>         boolean isPermanent =
> rs.getBoolean("isPermanent");
>     }
> %>
>  
> Then further down I do this
>  
> <%
>     if(isPermanent) {
> %>
>     <input type="checkbox"
> name="isPermanent" checked>
> <%
>     }
>     else {
> %>
>     <input type="checkbox"
> name="isPermanent">
> <%
>     }
> %>
>  
> When I first started working with the checkbox I expected it to have a

> value= option the way the other components do, but it doesn't appear 
> to
> work the way the other components work.    Or am I missing
> something?
>  
> Thanks
> 
> ---------------------------------------------------------------------
> 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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to