struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <newton.d...@yahoo.com>
Subject Re: Struts 1.2.9 and checkboxes
Date Tue, 25 Nov 2008 19:08:30 GMT
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 <DBarron@zencos.com> 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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message