problem with complex bean

Hi,

i'm newbie and i've got big problem

i have a database tables for a school, in one table there are the students, in the second courses and in third the marks

when i choose a particular student i want to see the table with all the courses and list of his marks in one row - something like that:

person : Peter Cichon

math 5,4,5,3 and button "add mark"

physics 5,6,5,4 and button "add mark"

and so on

i do not want to see it in this manner:

person : Peter Cichon

math 5

math 4

math5

math 3

physics 5

.....

is it possible to create a backing bean that will return the ..jstl.Result and use it in h:DataTable

thanks in advance and sorry for my english

peterc

[775 byte] By [pietruchaa] at [2007-11-26 15:57:29]
# 1

you should write backing bean method such that, it returns you the data in sequence you want.

For ex, you can write a method such that it returns you subject, math1,math2,.... so on...

& finally you retrieve each column object in <h:column> of dataTable.....

Hope I understood properly.....

ayananshua at 2007-7-8 22:18:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
it's a idea, but there is one problem, i don't know how many marks there will be in particular subjectpeterc
pietruchaa at 2007-7-8 22:18:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
You can nest DTO's and datatables.
BalusCa at 2007-7-8 22:18:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

thanks, but i dont know how - i'm beginner in java

in the bean i use something like this

public class MarksBean {........

.....

public Result getMarks() throws SQLException, NamingException {

try {

Context ctx = new InitialContext();

if (ctx == null) throw new NamingException("No initial context");

DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/school_");

if (ds == null) throw new NamingException("No data source");

Connection conn = ds.getConnection();

if (conn == null) throw new SQLException("No connection");

Statement sql = conn.createStatement();

ResultSet result = sql.executeQuery("select p.person_id, s.subject_id, m.mark_id from marks m , subject s, person p where person_id=1 and p.person_id - m.person_id and s.subject_id = m.subject_id");

return ResultSupport.toResult(result);

}

finally {

conn.close();

}

but (of course) this is not what i want - is it posible to change this in simple way to obtain data in the right way

my second question is : is it posible to make a Result not from MySQL Table but from MySQL View

once again sorry for my English

peterc

pietruchaa at 2007-7-8 22:18:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Yes , definitely, views are treated just like normal table. I think here the real problem is how to get data in desired format & not the JSF. You need to work on your database query, in order to get expected result-set.
ayananshua at 2007-7-8 22:18:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
thanks ayananshu and BalusC for helpi made a function in Mysql that retrieve all marks into list and use it in the MarksBeanthanks again
pietruchaa at 2007-7-8 22:18:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...