Menu

Using DBRows Within JSP

DBvolution objects can be used directly within JSP, with an important caveat:

You may need to add beaniness to your DBRow subclasses.

JSP has this strange behaviour of accessing fields as if they're fields but actually using get() and set() methods. So you can use the DBRow subclasses and access the fields easily but you'll get a strange error.

Personally I think it's a bug in JSP but I've been informed otherwise.

To fix the issue just use your IDE's refactoring mechanism to encapsulate the fields. You should leave the fields as public so DBV can access them properly.

public class Staff extends DBRow{

    @DBColumn("staff_id")
    public DBInteger staffID = new DBInteger();

}

If you used DBvolution's builtin class generator the above is what you have. To add support for JSP the below would be perfect.

public class Staff extends DBRow{

    @DBColumn("staff_id")
    public DBInteger staffID = new DBInteger();

    public Integer getStaffID(){
        return staffID.intValue();
    }

    public Integer setStaffID(Integer id){
        return staffID.setValue(id);
    }
}

Strangely JSP is fine with using QueryableDatatypes like DBInteger so even the following will work fine:

public class Staff extends DBRow{

    @DBColumn("staff_id")
    public DBInteger staffID = new DBInteger();

    public DBInteger getStaffID(){
        return staffID;
    }
}
Posted by Gregory Graham 2014-01-27

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.