cancel
Showing results for 
Search instead for 
Did you mean: 

TableViewModel -change header cell color

Former Member
0 Kudos
40

hi everyone,

i have created a TableViewModel with ALTERNATING design

can anyone tell how can i change the color of my header cell alone?

awaiting reply.

thanks in advance

SwarnaDeepika

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

Could u place your table view code here ..,

Thanx

Sreedhar

Former Member
0 Kudos

hi Sreedhar,

i have given the code for my JSP page below--

<hbj:tableView

id="mytableView"

model="tableBean.model"

design="ALTERNATING"

headerVisible="true"

footerVisible="true"

fillUpEmptyRows="true"

visibleFirstRow="1"

visibleRowCount="5"

navigationMode="BYLINE"

width="500 px">

</hbj:tableView>

i dont think there's any direct way to do that.plz help.

Regards

SwarnaDeepika

Former Member
0 Kudos

Hai,

Try This...

setStyleForCell

(int rowIndex, int colIndex

TableCellStyle.NEGATIVE)

Sreedhar G

Former Member
0 Kudos

hai,

but this is only for cells.

my header area will only contain a title of the table,how can i refer it thro row/column index?

Former Member
0 Kudos

I thing that the best way is to define your own header cell renderer. With this renderer you can render watever you want into header area.

Ahoj

Ondrej

Former Member
0 Kudos

hi Ondrej,

can u plz sent me some sample codes that use headercellrenderer because i've never used that before?

Regards

SwarnaDeepika

Former Member
0 Kudos

Each part of table has its own renderer so you have to know which part of table you want to render with your renderer. You can redefine:

HeaderRenderer

HeaderCellRenderer

CellRenderer

FooterRenderer

RowRenderer

...

Check Htmlb API for more details

And how to use it?

Wry simple Here is sample code in which I redefine more renderers:

.
.
.
// java file with TableView

			seznam = new TableView(ID_TBV_SEZNAM);
			seznam.setCellRenderer(new SeznamCellRenderer());
			seznam.setHeaderRenderer(new SeznamHeaderRenderer());
			seznam.setHeaderVisible(true);
			seznam.setFooterRenderer(new SeznamFooterRenderer());
			seznam.setFooterVisible(true);

.
.
.
// each renderer has its own java file like this
package cz.cez.km.message;

import java.text.SimpleDateFormat;

import com.sapportals.htmlb.Button;
import com.sapportals.htmlb.GridLayout;
import com.sapportals.htmlb.HTMLFragment;
import com.sapportals.htmlb.Link;
import com.sapportals.htmlb.TextView;
import com.sapportals.htmlb.rendering.IPageContext;
import com.sapportals.htmlb.table.ICellRenderer;
import com.sapportals.htmlb.table.TableView;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.portal.prt.component.IPortalComponentSession;

/**
 * Cell Renderer pro tabulku se seznamem zprav pro administratora<br>
 * 
 * @author Ondrej Dedina
 */
public class MessageAdminCellRenderer implements ICellRenderer {

	public void renderCell(int row, int column, TableView tableView, IPageContext rendererContext) {

		switch (column) {
			case 1 :
				SimpleDateFormat sdf = new SimpleDateFormat("d.M.yyyy");
				TextView tvDate = new TextView(sdf.format(Static.bigDecimalToDate(msg.getCreated_Tstmp())));
				tvDate.render(rendererContext);
				break;

			case 2 :
				Link link = new Link("msg" + row, msg.getSubject());
				link.setOnClientClick("window.open('/irj/servlet/prt/portal/prtroot/cz.cez.km.DisplayMessage?messageID=" + msg.getMessage_Id() + "', '_blank', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=700, height=500, left=50, top=50');");
				link.render(rendererContext);
				break;
				
			case 3 :
				Button btnEdit = new Button("edt" + msg.getMessage_Id(), Static.getTranslation("EDIT"));
				btnEdit.setOnClick(MessageAdmin.ACT_EDIT);
				Button btnDelete = new Button("del" + msg.getMessage_Id(), Static.getTranslation("DELETE"));
				btnDelete.setOnClick(MessageAdmin.ACT_DELETE);
				btnDelete.setOnClientClick("confirm_message_delete();");
				GridLayout glButtons = new GridLayout();
				glButtons.addComponent(1, 1, btnEdit);
				glButtons.addComponent(1, 2, new HTMLFragment(" "));
				glButtons.addComponent(1, 3, btnDelete);
				glButtons.render(rendererContext);
				break;				
		}
	}
}

So here you can see that you can render watever you want (like buttons, links, images, gridlayouts...)

Hope it helps!

Ahoj

ONDREJ

Former Member
0 Kudos

hi Ondrej,

can u plz send me the corresponding jsp part of header attribute ?

take for example that i am rendering it as a textview

TextView tv = new TextView("tv");

tv.setText("header title");

wat shld i give in header text attribute of tableView

<tableView

headerText="?????????"

/>

Message was edited by: swarnadeepika

Former Member
0 Kudos

Unfortunatelly not because I'm always using DynPage and not JSPDynPage.

O

Former Member
0 Kudos

Hi,

if Ondrej can't help, Romano comes with helping hand

Try this:

in JSP:


<%@ page import="com.yourcompany.HeaderRenderer"%>
...
<jsp:useBean id="tbl01" scope="session" class="com.yourcompany.beans.TableViewResources" />
...
<hbj:content id="myContext" >
<hbj:page title="Page">
...
<hbj:tableView
 id="tbl01_jsp"      
 model="tbl01.model"     
 design="<%=tbl01.getDesign() %>"
 headerVisible="<%=tbl01.isHeaderVisible() %>"
 footerVisible="<%=tbl01.isFooterVisible() %>"
 fillUpEmptyRows="<%=tbl01.isFillUpEmptyRows() %>"
 navigationMode="<%=tbl01.getNavigationMode() %>"
 selectionMode="<%=tbl01.getSelectionMode() %>"
 headerText="<%=tbl01.getHeaderText() %>"
 visibleFirstRow="<%=tbl01.getVisibleFirstRow() %>"
 width="<%=tbl01.getTableWidth() %>"
 onNavigate="myOnNavigate"> 
<%tbl01_jsp.setHeaderRenderer(new HeaderRenderer());%>
</hbj:tableView>
...
</hbj:page>
</hbj:content>

note the <b><%@ page import="com.yourcompany.HeaderRenderer"%></b> at the begining of the JSP and the <b><%tbl01_jsp.setHeaderRenderer(new HeaderRenderer());%></b> inside the table definition.

Then create a java class:

<b>com.yourcompany.HeaderRenderer</b>:

package com.yourcompany;

import com.sapportals.htmlb.*;
import com.sapportals.htmlb.enum.*;
import com.sapportals.htmlb.rendering.IPageContext;
import com.sapportals.htmlb.table.IHeaderRenderer;
import com.sapportals.htmlb.table.TableView;
import com.sapportals.portal.prt.component.IPortalComponentRequest;

public class HeaderRenderer implements IHeaderRenderer {

public void renderHeader(TableView tableView, IPageContext pcontext) {
    IPortalComponentRequest request =(IPortalComponentRequest) pcontext.getRequest();
      
    GridLayout gl = new GridLayout();
    gl.setCellPadding(10);
    
    TextView tv = new TextView();
    tv.setEncode(false);
    tv.setDesign(TextViewDesign.HEADER3);
    tv.setText("<span style="color=#FFFFFF">"+tableView.getHeaderText()+"</span>");
    tv.setWrapping(true);
    
    GridLayoutCell glc = new GridLayoutCell(tv);  
    gl.addCell(1,1,glc);
    gl.setWidth("100%");
    gl.render(pcontext);
	}

public boolean willRenderHeader(TableView tableView, IPageContext pcontext) {
    //allways render
	return true;
}

}

This one just renders the text inside the header in white, wrapped in GridLayout padded by 10px, but you can put anything of your own inside <b>renderHeader</b> method.

Romano

Former Member
0 Kudos

hi Romano

First of all thanks a lot for ur timely help.

in ur code ur retrieving value from a bean as ur headertext,i'm only hard-coding the values,

so that will be only difference.

but i'm getting only a blank header!

i'm sending the relevant parts of my code,plz tell me where am i going wrong?

jsp page----

<%@ taglib uri = "tagLib" prefix="hbj" %>

<%@ page import="HeaderPackage.HeaderRenderer"%>

<hbj:tableView

id="mytableView"

model="tableBean.model"

navigationMode="BYLINE"

headerText="My header area"

width="500 px">

<% mytableView.setHeaderRenderer(new HeaderRenderer());%>

</hbj:tableView>

HeaderRenderer.java----

public class HeaderRenderer implements IHeaderRenderer {

public void renderHeader(TableView tableView, IPageContext pcontext) {

IPortalComponentRequest request =(IPortalComponentRequest) pcontext.getRequest();

TextView tv = new TextView();

tv.setEncode(false);

tv.setDesign(TextViewDesign.HEADER3);

tv.setText("<center>"+tableView.getHeaderText()"</center>");

}

public boolean willRenderHeader(TableView tableView, IPageContext pcontext) {

return true;

}

Awaiting your reply

regards

SwarnaDeepika

Former Member
0 Kudos

Hi,

I think you forgot one important piece of code at the end of <b>renderHeader</b> method. This method replaces the rendering of the table header so render your content by calling (in your case):

tv.render(pcontext);

This outputs the content to the page.

Now it should be ok.

Romano

Former Member
0 Kudos

hi,

Thank you,once again!

its working fine now,but i have a general doubt,is there any way to change the background color of my header?

regards

SwarnaDeepika

Former Member
0 Kudos

Hmmm,

I'm not sure but you can try in renderHeader (not tested):

String html = "<table width="100%" height="100%" style="border:1 solid #E48D06; background-color:#FCD016 "><tr><td><center><span class=urTxtH3>Some header text</span></center></td></tr></table>";

HTMLFragment htmlFrag = new HTMLFragment(html);
htmlFrag.render(pContext);

Or something like this...

Romano

Answers (0)