开发者

Newbie to JSF - Add Grid to Datatable

开发者 https://www.devze.com 2022-12-15 11:37 出处:网络
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).

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 se开发者_运维百科e 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>


  • <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)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号