From: tomo on
I want to dynamically create a large form in JSF, looking something like
this which will have at least 200 rows.

COL1 COL2 COL3
ROWNAME inputText inputText inputText .
. . . .
.

I want to generate it from db, by putting rownames and column names in
some lookup table. I'm using ArrayList with this structure to generate
this :

class Form{

private rowName;
privae columnOne;
private columnTwo;
private columnThree;


}

And it works fine, only that other day I had a request to put some
inputText to sum some values beetween row 50 and 51, and I couldn't do
that because the whole form
is dynamically generated from db. Is it better to write all 200 rows
with inputTexts and outputText elements instead of using datatable
structure for easier changing ?


Thanks in advance.


From: tomo on
Or is it better to write static .jspx which is harder to write (at least
200 rows) , but it's easily changed when i need to add some custom row ?

From: markspace on
tomo wrote:
> Or is it better to write static .jspx which is harder to write (at least
> 200 rows) , but it's easily changed when i need to add some custom row ?
>


Almost certainly not this.

I'd go 100% in the opposite direction, I think. Consider something like
this for your big form:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<body>
${bigForm}
</body>
</html>


Now, your big form view (HTML rendering) is as dumb as can be, and so
never needs to be changed (hopefully). Write a simple
bigForm.toString() routine for rendering a table as HTML by calling the
toString() of the objects in the table. Then if you need to treat a row
specially, you inject objects at that row that are different.

This all happens in the controller (and model objects) where you have
the easiest time with unit testing and creating different sorts of
objects. Since you seem to have changing requirements for this part of
the system, making it as flexible as possible seems like one way to keep
the code under control.