简体   繁体   English

具有动态列的可编辑数据表

[英]Editable datatable with dynamic columns

I have a Seam 2.2 JSF 1.2 application deployed on JBoss 5. I need to create a page with a complex, editable datatable; 我已经在JBoss 5上部署了一个Seam 2.2 JSF 1.2应用程序。我需要创建一个包含复杂的可编辑数据表的页面。 data is displayed across as well as down. 数据在上下显示。

I have an employee: 我有一个员工:

Employee {
    int id;
    String name;
    ...
}

I have certification types: 我有认证类型:

Certs {
    int id;
    String certType;
    ...
)

and I have events of type Certs held by employees: 我有员工举办的证书类型的活动:

Events {
    int id;
    int employeeId;
    int certId;
    Date start;
    Date end;
    ...
}  

I need to display the data across by dynamically generated cert type (number of cert columns are not known til the user selects them), if multiple cert types are selected and an employee has no event for that cert type the cells for that cert type should be empty. 我需要按动态生成的证书类型显示数据(直到用户选择它们为止,证书列的数目是未知的),如果选择了多种证书类型,并且员工没有该证书类型的事件,则该证书类型的单元格应该是空的。

有效的XHTML

I can generate the correct format using rich:datatable with rich:columns and rich:column, but that's only display - I need to be able to edit the rows in place. 我可以使用带有rich:columns和rich:column的rich:datatable生成正确的格式,但这仅是显示-我需要能够就地编辑行。

I'm working on generating the table in the backing bean using HtmlDataTable, but Seam does not play well with JSF binding. 我正在使用HtmlDataTable在支持bean中生成表,但是Seam在JSF绑定中不能很好地发挥作用。

The hardest bit for me to wrap my head around is making vertical data (an employee with related event information, one row for every event) horizontal (an employee event event event). 对于我来说,最难的是使垂直数据(具有相关事件信息的员工,每个事件一行)水平(员工事件事件)。

Anybody have any recommendations or advice on the best way to approach this efficiently? 有人对有效解决此问题的最佳方法有任何建议或意见吗?

I'll post what I've tried, but this is pretty long already, so I'll add more as needed. 我将发布我尝试过的内容,但这已经很长了,因此我将根据需要添加更多内容。

What I ended up doing was using a combination of components to make this work. 我最终要做的是使用多种组件来完成这项工作。 I created an object that converts rows of employee data into one row. 我创建了一个将员工数据行转换为一行的对象。 So data from the db that returns: Jones certtype1 start end 因此,从数据库返回的数据将返回:Jones certtype1 start end

Jones certtype2 start end 琼斯certtype2开始结束

Jones certtype3 start end 琼斯certtype3开始结束

Becomes: 成为:

Jones certtype1(start, end) certtype2(start, end) certtype3(start, end) 琼斯certtype1(开始,结束)certtype2(开始,结束)certtype3(开始,结束)

And organized it like: 并像这样组织:

 <rich:dataTable id="acadCertList"
value="#{myCertBean.employeeCertEventObjects}"
var="_certs" rowKeyVar="row" >

  <f:facet name="header">

<rich:columnGroup>
    <rich:column>
        <h:outputText value="Row" />
    </rich:column>
    <rich:column>
    <h:outputText value="Name" />
    </rich:column>

  <!-- dynamically create the certType1, certType2 …  column headers -->
    <rich:columns value="#{myCertBean.selectedCertTypeList}"
            var="_selCrtType" colspan="2">
        <h:outputText value="#{_selCrtType.certType}" />
    </rich:columns>
</rich:columnGroup>
 </f:facet>

 <rich:subTable value="#{_certs}" var="_cEmpObj">
<f:facet name="header">
  <!-- repeat start end column headers for each certType -->

    <rich:columnGroup>
        <rich:column>
 </rich:column>
        <rich:column>
        </rich:column>
        <c:forEach items="#{myCertBean.selectedCertTypeList}">
 <rich:column>
                <h:outputText value="Start" />
            </rich:column>
 <rich:column 
                <h:outputText value="End" />
            </rich:column>
 </c:forEach>
    </rich:columnGroup>
</f:facet>
 <!-- load data for each row -->

<rich:column id="row_#{row}">
    <h:outputText value="#{row+1}" />
</rich:column>
<rich:column id="name_#{row}">
    <h:outputText value="#{_cEmpObj.name}/>
</rich:column>

<c:forEach items="#{myCertBean.selectedCertTypeList}" varStatus="status">
    <rich:column id="curexp_#{status.index}" 
        <h:outputText
 value="#{_cEmpObj.certEventsByCertTypeSysid[status.index].startDate}" />
    </rich:column>
    <rich:column id="curexp_#{status.index}" 
        <h:outputText
 value="#{_cEmpObj.certEventsByCertTypeSysid[status.index].endDate}" />
    </rich:column>
 </c:forEach> 

 </rich:subTable>

 </rich:dataTable>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM