在系统的一览画面,我们有时候希望有的行的数据根据数据性质的不同而显示不同的颜色,
Dinamica 默认只是处理的行的交叉色。
其他定制需要自己实现。
system win xp JP
Dinamica 2.1.4 with Ajax support.
正常的一览画面的显示部分,
调用的是默认的action GenericOutput 。
配置文件部分如下:
<output> <classname>dinamica.GenericOutput</classname> <template>template.htm</template> <set-http-headers>true</set-http-headers> <content-type>text/html</content-type>
现在我们进行定制,
从GenericOutput继承一个新的类MyGenericOutput 。
基类GenericOutput的onNewRow 方法 如下所示:
public String onNewRow(Recordset rs, String rowTemplate) throws Throwable
{
/*
* This code is used to alternate row colors,
* the row template must include the special
* field marker ${fld:_rowStyle} which will be replaced
* by the style parameters set in web.xml.
*/
String style1 = getContext().getInitParameter("def-color1");
String style2 = getContext().getInitParameter("def-color2");
String currentStyle="";
if (rowColor==0)
{
rowColor=1;
currentStyle = style1;
}
else
{
rowColor=0;
currentStyle = style2;
}
rowTemplate = StringUtil.replace(rowTemplate, "${fld:_rowStyle}", currentStyle);
return rowTemplate;
}
我们需要对onNewRow方法进行重写
public String onNewRow(Recordset rs, String rowTemplate) throws Throwable { String style1 = getContext().getInitParameter("def-color1"); String style2 = getContext().getInitParameter("def-color2"); String currentStyle=""; if (EWWBDef.DATA_UPD_TYP_ADD.equals(rs.getValue("data_upd_typ"))) { currentStyle = "class='specColor1'" ; rowTemplate = StringUtil.replace(rowTemplate, "${fld:_rowStyle}", currentStyle); return rowTemplate; } else if (EWWBDef.DATA_UPD_TYP_UPD.equals(rs.getValue("data_upd_typ"))) { currentStyle = "class='specColor2'" ; rowTemplate = StringUtil.replace(rowTemplate, "${fld:_rowStyle}", currentStyle); return rowTemplate; } else if (EWWBDef.DATA_UPD_TYP_DEL.equals(rs.getValue("data_upd_typ"))) { currentStyle = "class='specColor3" ; rowTemplate = StringUtil.replace(rowTemplate, "${fld:_rowStyle}", currentStyle); return rowTemplate; } else { return super.onNewRow(rs, rowTemplate) ; } }
上面的specColor1 ,specColor2,specColor3 需要在default.css中定制,
如下所示:
.grid tr.specColor1 td { background-color:#FFFFCC; }
.grid tr.specColor2 td { background-color:#FAC5DA; }
.grid tr.specColor3 td { background-color:#CC9900; }
经过上面的修改就可以按照自己的要求定制行的颜色了。
最后不能忘了,在config.xml中配置调用新做成的class.不是默认的那个GenericOutput。