Color per cell

UI Components for JSF
Post Reply
mikloman
Posts: 27
Joined: 18 Nov 2009, 00:23

30 May 2010, 11:52

Hello
i have a question.. I didnt find out, how i must realise somtehing that i could set for eache cell a own color. Now i had tried to make a new Attribute in the p:colums tag myself to add a new Attribute called colorPerCell. The idea is, that i could see a Methodeexpressen, whiche return a color, like red for example. In the DatatableRenderer.java i have insertet a new line, where the td-tag is rendered. Means in encodeTable(). But my Problem is, that the attribute never will be rendered on page. Could it be, that the yui-framwork override this attribut? And would it be possible to call this methode after yui has formattet the table. ..

Further a problem withe the p:printer-tag will be solved to for me. Because if i could add the display:none in the rowInde-Row, than the p:printer want print this td-tag. otherwise i thinke, that the jqprinter-script didnt realise, that in the css of yui this row will be hidden. Because for me , until knp0ow, that attibute will be printet too.

Here the source:

int ColumTag.java

Code: Select all

 private javax.el.ValueExpression _colorPerCell;
and the things which are used...


encodeTable() from DatadableRenderer.java
//only two new lines... but they will now be shown on page, why???a

Code: Select all

protected void encodeTable(FacesContext facesContext, DataTable dataTable) throws IOException {
                System.out.println("encodeTable(FacesContext facesContext, DataTable dataTable)");
		ResponseWriter writer = facesContext.getResponseWriter();
		String clientId = dataTable.getClientId(facesContext);
		Object selection = dataTable.getSelection();
		boolean selectionEnabled = dataTable.isSelectionEnabled() && selection != null;
		boolean isSingleSelection = dataTable.isSingleSelectionMode();

		if(dataTable.isLazy() && dataTable.getValue() instanceof LazyDataModel<?>) {
			dataTable.loadLazyData();
		}
		
		writer.startElement("table", null);
		writer.writeAttribute("id", clientId + "_table", null);
		writer.writeAttribute("style", "display:none", null);
		
		writer.startElement("tbody", null);
		
		int rowCountToRender = getNumberOfRowsToRender(dataTable);
		int first = dataTable.getFirst();
		
		for(int i = first; i < (first + rowCountToRender); i++) {
			dataTable.setRowIndex(i);
			if(!dataTable.isRowAvailable())
				continue;
			
			// Selection
			if(selectionEnabled && isSelected(dataTable.getRowData(), selection, isSingleSelection)) {
				dataTable.getSelectedRowIndexes().add(dataTable.getRowIndex());
			}
			
			// Row index var
			if(dataTable.getRowIndexVar() != null) {
				facesContext.getExternalContext().getRequestMap().put(dataTable.getRowIndexVar(), i);
			}
			
			writer.startElement("tr", null);
			
			//rowIndex
			writer.startElement("td", null);
			writer.writeAttribute("style", "display:none", null);
                        System.out.println("Set the style on display:none");
                        writer.write(String.valueOf(dataTable.getRowIndex()));
			writer.endElement("td");
			
			for(Iterator<UIComponent> iterator = dataTable.getChildren().iterator(); iterator.hasNext();) {
				UIComponent kid = iterator.next();
				
				if(kid.isRendered() && kid instanceof Column) {
					Column column = (Column) kid;
					writer.startElement("td", null);
                                        writer.writeAttribute("style", "background-color:"+column.getColorPerCell(), null);
                                        System.out.println("background-color:"+column.getColorPerCell());
					renderChildren(facesContext, column);
					writer.endElement("td");
				}
			}
			
			writer.endElement("tr");
		}

Thanks
Manuel

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

30 May 2010, 17:39

Yes, usually YUI datatable widget overrides the rendered table as widget uses table only to create a recordset and applies it's own stuff to create a new table.

Maybe you can use a similar approach as described in;

http://developer.yahoo.com/yui/examples ... oring.html

There is a formatCell api as well, for more info;

http://developer.yahoo.com/yui/docs/YAH ... Table.html

mikloman
Posts: 27
Joined: 18 Nov 2009, 00:23

03 Jun 2010, 00:47

Hi..
i think solved for me.....

I think I have a solution. It works very well for me.
I have now a new attribute, means <p:column colorPerCell={#item.colorStyle}. So a backingbean is called where return a string with the color. It must be a css-color.
Further i have in the datatablerenderer.java a new <input type=hidden> where i will render inside the body of the td-attribute. So the javascirpt of yui will not delete this one. Further i have in the Datatable defined a new formatter, which format every cell with the value of this hidden-field. So for me is possible to add with a small javascript to add the right color per cell to table. Its very well feature i think.
Pherheps it will be a workaround for primefaces too... Ok its very early stage. And my javascript-knowledge is not as well as it should be for things with yui...hmm.

Greats
Mikloman

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

04 Jun 2010, 11:21

We can add rowFormatter and cellFormatter methods to datatable, call them get the color and use the datatable apis directly as well.

Also there is an issue related to this already;

http://code.google.com/p/primefaces/iss ... ail?id=778

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 43 guests