Dear All, I'm working to create dbforms with a clear separation between presentation and logic. To do so I would JSTL for the presentation layer inside the dbform... then a java class to extract the scripting from the JSP. I would "include" that class in the page encapsulating it in a bean.
Now I'm creating an example based on bookstore where I've added 3 tables CUSTOMERS, LIBRARY (the libraries) and CUSTOMER_LIBRARY that is a n-m relation. I have a problem to access via JSTL to the properties of the currentRow to extract the current value of the fields. I put here the code of my JSP for a simple jdbform page where I try to access to the currentRow_CUSTOMER.CUSTOMER_ID property from JSTL and with the "classic" currentRow_CUSTOMER.get("CUSTOMER_ID"). My JSTL access returns a value for the CUSTOMER_ID that equals to currentRow_CUSTOMER.get("CUSTOMER_ID") + 1!!! Of course the method I'm using to access to the properties of the currentRow via JSTL are not correct... In this example I use a java class (the bean backcolor) only to create an alternate "color" table for the different records of the table... Could you have a check? Many thanx. Ivan --------------- CODE ------------------------------------ ivanCustomerJSTL_Bean.jsp <html> <%@ taglib uri="/WEB-INF/dbforms.tld" prefix="db" %> <%@ taglib uri="/jstl-c" prefix="c" %> <jsp:useBean id="backcolor" scope="page" class="Xoft.IvanBackgroudColor"/> <!-- To use the bean in JSTL i have to define a variable with jstl c:set var filled with the value of the bean. In this way later I could access to the properties of that bean --> <c:set var="backcolor" value="${backcolor}" /> <head> <script src ="/bookstore/jscal/calendar.js" type="text/javascript"></script> <db:base /> <target="_top"> </head> <body> <db:dbform autoUpdate="false" maxRows="*" tableName="CUSTOMER" > <db:header> <h1 align="center">Edit Customers</h1> <p align="center">Using simple dbform on simple table. maxRows=1; allowNew=true; autoUpdate=false</p> <table class="fixed" align="center"> <db:errors/> </db:header> <db:body allowNew="true"> <c:out value="${currentRow_CUSTOMER}" /> <br/>Setting the idNumber via scripting; <% backcolor.setIdNumber((int) Integer.parseInt((String)currentRow_CUSTOMER.get("CUSTOMER_ID"))); out.println("<br/> Test current ID: " + (String)currentRow_CUSTOMER.get("CUSTOMER_ID")); %> <c:out value="${backcolor.idNumber}" /> <br/> <!-- sets the idNumber property of the bean via JSTL SYNTAX --> Setting the idNumber via jstl syntax: <c:set target="${backcolor}" property="idNumber" value="${currentRow_CUSTOMER.CUSTOMER_ID}" /> <c:out value="${backcolor.idNumber}" /> <br/>getBgColor via scripting: <%=backcolor.getBgColor() %> <c:out value="${backcolor.bgColor}" /> <!-- sets the value of the bean via BEAN syntax --> <jsp:setProperty name="backcolor" property="idNumber" value="3" /> <br/>Id Number setted by setProperty fixed value 3- BEAN SYNTAX - <c:out value="${backcolor.idNumber}" /> <!-- sets the value of the bean via JSTL syntax --> <br/>Id Number setted by jstl set fixed value 4-JSTL SYNTAX, with previous initializaziton - <c:set target="${backcolor}" property="idNumber" value="4" /> <c:out value="${backcolor.idNumber}" /> <!-- Body --> <tr class="even" bgcolor=<c:out value="${backcolor.bgColor}"/> > <td style="width:300px">ID</td> <td style="width:100px"> JSTL_ID: <c:out value="${currentRow_CUSTOMER.CUSTOMER_ID}" /> DBFORMS_ID: <db:label fieldName="CUSTOMER_ID" /> </td> </tr> <tr class="even" bgcolor=<c:out value="${backcolor.bgColor}"/> > <td>CUSTOMER NAME</td> <td><db:textField size="25" fieldName="NAME"/> </td> </tr> <tr class="even" bgcolor=<c:out value="${backcolor}"/> class="button"> <td colspan="2" style="text-align:center"> <db:updateButton style="width:100" caption="Save"/> <db:deleteButton style="width:100" caption="Delete"/> <db:insertButton style="width:100" caption="Insert" showAlways="false" /> </td> </tr> <tr> <td colspan="2"><hr/></td> </tr> </db:body> <db:footer> <tr class="button"> <td colspan="2" style="text-align:center"><db:navFirstButton style="width:100" caption="<< First"/> <db:navPrevButton style="width:100" caption="< Previous"/> <db:navNextButton style="width:100" caption="> Next"/> <db:navLastButton style="width:100" caption=">> Last"/> <db:navNewButton style="width:100" caption="New" showAlwaysInFooter="false"/> <db:navCopyButton style="width:100" caption="Copy" showAlwaysInFooter="false"/> </td> </tr> </table> </db:footer> </db:dbform> <%@ include file="httpSnooper.jsp" %> <!-- Body end --> </body> </html> ----------------------------------------------------------------------- IvanBackgroundColor.java - the bean - /* * Created on Jul 4, 2004 * * Test per bean */ package Xoft; /** * @author [EMAIL PROTECTED] * * Simple class to create background color. */ public class IvanBackgroudColor { private String BG_LIGHT; private String BG_DARK; private String bgColor; private int idNumber; /** * @param ID_Number */ public IvanBackgroudColor() { BG_LIGHT="#EEEEEE"; BG_DARK="#666666"; } /** * @param idNumber The idNumber to set. */ public void setIdNumber(int idNumber) { this.idNumber = idNumber; } /** * @return Returns the idNumber. */ public int getIdNumber() { return idNumber; } /** * @return Returns the bgColor. */ public String getBgColor() { if (this.idNumber % 2 ==1) this.bgColor=BG_DARK; else this.bgColor=BG_LIGHT; return bgColor; } } ------------------------------------------------------------------------ A piece of code added to bookstore.script to create the new tables: CREATE TABLE LIBRARY(LIBRARY_ID INTEGER NOT NULL IDENTITY PRIMARY KEY, COMPANYNAME VARCHAR(50) NOT NULL) CREATE TABLE CUSTOMER(CUSTOMER_ID INTEGER NOT NULL IDENTITY PRIMARY KEY, NAME VARCHAR(50) NOT NULL) CREATE TABLE CUSTOMER_LIBRARY(CUSTOMER_ID INTEGER NOT NULL, LIBRARY_ID INTEGER NOT NULL) INSERT INTO LIBRARY VALUES(1,'First Library inc') INSERT INTO LIBRARY VALUES(2,'Second Library inc') INSERT INTO CUSTOMER VALUES(1,'First customer John Kazzus') INSERT INTO CUSTOMER VALUES(2,'Second customer Joanna LaSilona') INSERT INTO CUSTOMER VALUES(3,'Third customer Alabao Masino') INSERT INTO CUSTOMER VALUES(4,'Fourth customer Meo Mara') INSERT INTO CUSTOMER_LIBRARY VALUES(1,1) INSERT INTO CUSTOMER_LIBRARY VALUES(1,2) INSERT INTO CUSTOMER_LIBRARY VALUES(2,3) INSERT INTO CUSTOMER_LIBRARY VALUES(2,4) INSERT INTO CUSTOMER_LIBRARY VALUES(2,2) --------------------------------------------------------------------- Piece of XML added to dbforms-config.xml of the bookstore exmample <table name="LIBRARY"> <field name="LIBRARY_ID" fieldType="int" isKey="true" autoInc="true"/> <field name="COMPANYNAME" fieldType="varchar" sortable="true"/> </table> <table name="CUSTOMER"> <field name="CUSTOMER_ID" fieldType="int" isKey="true" autoInc="true"/> <field name="NAME" fieldType="varchar" sortable="true"/> </table> <table name="CUSTOMER_LIBRARY"> <field name="LIBRARY_ID" fieldType="int" isKey="true" /> <field name="CUSTOMER_ID" fieldType="int" isKey="true" /> </table> ============== END ============================================== p.s. Sorry for this "long" message. Thanx ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com _______________________________________________ DbForms Mailing List http://www.wap-force.net/dbforms