【问题标题】:How to make colspan with display:column如何使用 display:column 制作 colspan
【发布时间】:2013-12-15 11:35:26
【问题描述】:

我想在 display:column 中创建一个colspan,所以我尝试按如下方式进行:

<display:column style="width=50% colspan=2 " title="${textResources['Exam.endDate']}"> 

但它不起作用,似乎在 display:column 中不允许使用此属性,那么该怎么做呢?

【问题讨论】:

  • 你在使用 displayTag 吗??

标签: java jsp el jsp-tags displaytag


【解决方案1】:

要向显示列添加 colspan,您必须创建一个 Table Decorator 扩展 TableDecorator 类,覆盖方法 init,在此方法中您需要获取单元格的标题并添加 colspan 属性。

package org.hannibal.utils.view.decorators;    
import java.util.List;

import javax.servlet.jsp.PageContext;

import org.displaytag.decorator.TableDecorator;
import org.displaytag.model.HeaderCell;
import org.displaytag.model.TableModel;
import org.displaytag.util.HtmlAttributeMap;

public class ColspanTableDecorator extends TableDecorator {

    @Override
    public void init(PageContext pageContext, Object decorated,
            TableModel tableModel) {
        super.init(pageContext, decorated, tableModel);
        List headersList = tableModel.getHeaderCellList(); 
        HeaderCell myHeader = (HeaderCell)headersList.get(0);
        HtmlAttributeMap map = myHeader.getHeaderAttributes();
        map.put("colSpan", "2");            
    }   
}

在jsp中我也是这么用的。

<display:table name="sessionScope.employees" pagesize="10" cellpadding="2" cellspacing="0"
        decorator="org.hannibal.utils.view.decorators.ColspanTableDecorator">

希望对你有帮助

【讨论】:

  • 什么是myHeader,请给更详细的解答
  • 就我而言,我会将装饰器属性添加到 display:column 而不是 dipslay:table
  • 不行你要加到展示台上,我不确定有没有ColumnDecorator,我用展示台的装饰器测试一下
  • 但我希望 colspan 行为适用于特定列而不是所有列
  • 由于 java.lang.ClassCastException 异常而无法使用 ColspanTableDecorator
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-05-27
  • 2013-04-20
  • 1970-01-01
  • 1970-01-01
  • 2013-07-23
  • 2021-12-20
  • 2016-06-26
相关资源
最近更新 更多