jsf big form

T

tomo

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.
 
D

Danno

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.

Well, first of all, most of the time when you find yourself naming
things columnOne, columnTwo, columnThree you are doing something
wrong. May I recommend the following.

public class DynamicData { //Best if you name it something with
meaning e.g. Accounts
private List<String> columnTitles;
private List<List<String>> data;

public List<List<String>> getData() {
return data;
}

public List<String> getColumnTitles() {
return columnTitles;
}

//...setters and adders
//...use checks to make sure your data does go under or over column
name list widths
}

Now onto JSF: Since Datatable doesn't do so well for dynamic sized
data, I believe you can just use XHTML & Facelets (which I hope you
are using):


<table id = "myTable">
<tr>
<ui:repeat value="#{dynamicData.columnTitles}"
var="columnTitle">
<td><h:eek:utputText value="#{columnTitle}"/></td>
</ui:repeat>
<tr>
<ui:repeat value="#{dynamicData.data}" var="#{rowData}">
<tr>
<ui:repeat value="#{rowData}" var="{eachColumnData}">
<td><h:eek:utputText value="#{eachColumnData}"/></td>
</ui:repeat>
</tr>
</ui:repeat>
</table>


Of course, I did not run this, this just came out of my brain (or
ass ;) ), so you may have to play with it some til you get what need.
Hope this helps. Let me know either way, since I haven't done dynamic
sized data tables in JSF.
 
T

tomo

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 ?
 
M

markspace

tomo said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top