Hi there,
I am using MS SQL Server 2000 with DbForms 1.1.3. I have a few boolean
fields in my database, which are meant to be represented by the java SQL BIT
type. However, DbForms appears not to have support for BIT yet. The behavior
of these BIT fields is strange enough so I can't implement them with the
current checkboxes myself. Say I have a <db:checkbox value="1" novalue="0"
fieldName="booleanField"/> - the values in the database won't feed the
checkbox. By using a db:label I determined that the value my JDBC driver
delivers for "1" in the database ends up being "true" whereas the
"unchecked" value, "0" will be delivered as "false". However, when I want to
enter data into the database I have to send "1" or "0" rather than those
strings, otherwise I will get a JDBC error from the driver.
I think BIT can be represented if db:checkbox gets two new attributes,
"sendvalue" and "sendnovalue".
F.i. <db:checkbox value="true" sendvalue="1" "novalue="false"
sendnovalue="0" fieldName="booleanField"/>
Reading data works like before for db:checkbox, but rendering inserts the
value of "sendvalue" and "sendnovalue" instead. I am not sure if this will
help anybody else because I can't test if any other databases/drivers have a
similar behavior. I also didn't get to test this much (it definitely works
for me, with a single checkbox), but I submit it anyway in the hopes that
somebody might find it useful. I have added the new attributes for the
checkbox tag in taglib_docu.xml plus a diff against
* $Header:
/cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbCheckboxTag.java,v 1.8
2003/01/23 15:05:59 hkollmann Exp $
* $Revision: 1.8 $
* $Date: 2003/01/23 15:05:59 $
Regards,
Sebastian Scheible
<attribute>
<name>sendvalue</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<info>
<p>value that should be sent back to the database if checked,
</p>
<p>overrides value. might help getting along with BIT values
</p>
<p>that read "true"/"false" but need to send back "1"/"0"</p>
</info>
</attribute>
<attribute>
<name>sendnovalue</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<info>
<p>value that should be sent back to the database if not
checked, </p>
<p>overrides novalue. might help getting along with BIT values
</p>
<p>that read "true"/"false" but need to send back "1"/"0"</p>
</info>
</attribute>
diff -u -wb ~/DbCheckboxTag.java src/org/dbforms/taglib/DbCheckboxTag.java
--- /root/DbCheckboxTag.java 2003-08-14 14:36:00.000000000 +0200
+++ src/org/dbforms/taglib/DbCheckboxTag.java 2003-08-14
14:56:57.000000000 +0200
@@ -50,6 +50,8 @@
private String growDirection; // only needed if we habe a whole "group"
of DbRadioTags; default = null == horizontal
private String growSize = "0"; // only needed if we habe a whole
"group" of DbRadioTags; default = 1
private String noValue;
+ private String sendValue;
+ private String sendNoValue;
/**
* DOCUMENT ME!
@@ -166,7 +168,14 @@
tagBuf.append("<input type=\"checkbox\" name=\"");
tagBuf.append(getFormFieldName());
tagBuf.append("\" value =\"");
+ if (!Util.isNull(getSendvalue()))
+ {
+ tagBuf.append(getSendvalue());
+ }
+ else
+ {
tagBuf.append(value);
+ }
tagBuf.append("\" ");
if (selected)
@@ -237,15 +246,20 @@
setOnClick("this.checked=" + isSelected + ";" + onclick);
}
tagBuf.append(generateTagString(value, "", isSelected));
- if (!Util.isNull(getNovalue())) {
tagBuf.append("<input type=\"hidden\" name=\"");
tagBuf.append(getFormFieldName());
tagBuf.append("\" value =\"");
+ if (!Util.isNull(getSendnovalue()))
+ {
+ tagBuf.append(getSendnovalue());
+ }
+ else if (!Util.isNull(getNovalue()))
+ {
tagBuf.append(getNovalue());
+ }
tagBuf.append("\" ");
tagBuf.append("/>");
}
- }
else
{
int embeddedDataSize = embeddedData.size();
@@ -311,4 +325,35 @@
this.noValue = noValue;
}
+ /**
+ * Returns the sendValue.
+ * @return String
+ */
+ public String getSendvalue() {
+ return sendValue;
+ }
+
+ /**
+ * Sets the sendValue.
+ * @param sendValue The sendValue to set
+ */
+ public void setSendvalue(String sendValue) {
+ this.sendValue = sendValue;
+ }
+
+ /**
+ * Returns the sendNoValue.
+ * @return String
+ */
+ public String getSendnovalue() {
+ return sendNoValue;
+ }
+
+ /**
+ * Sets the sendNoValue.
+ * @param sendNoValue The sendNoValue to set
+ */
+ public void setSendnovalue(String sendNoValue) {
+ this.sendNoValue = sendNoValue;
+ }
}
\ No newline at end of file
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
DbForms Mailing List
http://www.wap-force.net/dbforms