tags:

views:

314

answers:

2

Hi,

I have this datatable with dynamic columns in my application. I'm trying to figure out why it shows up with no grid. (And how to enable grid for the datatable).

The JSP: (You can see a few attempts I made, which failed)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Celsius to Fahrenheit Convertor</title>
</head>
<body>
<f:view>
    <h:form styleClass="list-background">
        <h:panelGrid footerClass="subtitle"  styleClass="list-background"
            headerClass="subtitlebig" styleClass="medium"
            columnClasses="subtitle,medium">
                <h:panelGroup binding="#{myBean.dynamicDataTableGroup}" />
        </h:panelGrid>
        <h:commandButton value="Add" action="#{myBean.add}" />
    </h:form>
</f:view>
</body>
</html>
+1  A: 
  • <h:panelGrid> is not a grid in the traditional UI sense (i.e. a table with editable fields) - it renders as an HTML <table> (as written in the docs)
  • since you don't have a <h:dataTable> .. you can't have a dataTable
  • in order to achieve a grid in the traditional sense, take a look at this, but have in mind it won't be easy for a beginner.
  • if you want just dynamically rendered table, check this example (or google more)
Bozho
Thank you.I found the tutorial from SUN (http://java.sun.com/javaee/5/docs/tutorial/doc/bnarf.html#bnarj) and I will read it.The real problem with alot these technologies, in my opinion, is that begginers, often don't know where to look for information or even what questions to ask whereas people with knowledge or 'pros' disregard simple questions because "You can google it". (I'm not complaining or anything, just trying to fill the gap that I see on many questions asked on this website and anywhere. I do appreciate your answer and it helped me focus on "what to look for")Thanks!
Ben
in that case the protocol is to at least upvote the answer ;)The problem with beginners is that they don't know where to look - quite correct, but quite their own fault - the immediate product documentation (JSF tutorial in this case, a "User guide" in other cases) is the first place to look at.
Bozho
I marked it as the answer although the best answer for a newbie question like this, I believe, would have been "You missed the point of how this works, you should read X to understand the basics and then go back to the problem". Telling me to go google it as not helpful if I don't know where to look (Even documentation is not the right place to look for because it is not intended for begginers but for people who know what theyre looking for. The Sun tutorial is ideal for this purpose and only by accident I found it)
Ben
A: 

From the comments:

Well, that's just a button that add a line to the table.

Then you don't necessarily need a "dynamic datatable" (this is only useful if the columns are unknown beforehand --which is also explained in the article's text). Just the <h:dataTable> is enough. It is backed by a List<RowObject>. On the add button you basically just need to add a new RowObject to the List (and keep a counter in the request scope so that JSF knows with how many items it should prepare the list). That's basically all. It's described with an example in the same "Using datatables" article under the chapter "Add new rows to datatable".

BalusC