Displaying Flag in a table corresponding to a DB value ?!

Hi forum,

It's somehow a complicated problem !!

I don't know to start from where

I want to get a field value from each record in a table DataProvider

and according to each value I want to perform an action on the table

In more details I want to display a flag image instead of the value itself corresponding to the field record value returned

I used this code in the Page Bean to get each record value as follows:

publicvoid statusFlag()

{

// Set cursor to first row

search_vwDataProvider.cursorFirst();

while(true)

{

// Get StatusID from current row

search_vwDataProvider.refresh();

RowKey rowKey = search_vwDataProvider.getCursorRow();

Integer StatusID = (Integer)search_vwDataProvider.getValue("candidate_status_vw.employment_level_id", rowKey);

if (StatusID.equals(new Integer(1)))

getLoginSessionBean().setStatus_img("Flag-orange.jpg");

else

getLoginSessionBean().setStatus_img("Flag-grey.jpg");

// Check if current row is the last or not

if (search_vwDataProvider.cursorLast())

{

search_vwDataProvider.refresh();

break;

}

// Move the cursor to the next row

search_vwDataProvider.cursorNext();

}

}

ofcourse the above function is called in the prerender Function

and I added this code to the loginSessionBean (aka sessionBean)

to set & get the flag image url

private String status_img;

public String getStatus_img()

{

return ("/resources/" + this.status_img);

}

publicvoid setStatus_img(String status_img)

{

this.status_img = status_img;

}

Then binded the image url in the table field to getStatus_img() function as shown

<ui:image binding="#{searchResults.image1}" id="image1" url="#{LoginSessionBean.status_img}"/>

it appears from the returned image that the while loop above runs for the first row only causing all later images column be the same as the first row

Please advise is it possible to overcome that using a Java code

or should I use a JavaScript code in the page's JSP

Thanks in advance,

Amr Aman.

[3266 byte] By [sotota] at [2007-11-26 20:07:06]
# 1

There is how to display flag in a table corresponding to a DB value:

1. Add a column of Image component to the table and then add a method to get image URL corresponding to the DB value in the page. For example:

public String getURL(){

String name = (String) getValue("#{currentRow.value['PERSON.NAME']}");

if ((name != null) && (name.startsWith("Black") || name.startsWith("Chen"))){

return "/resources/red.PNG";

}else{

return "/resources/green.PNG";

}

2. Bind the image's url property (created in step1) to the URL in page by clicking image node in the outline window and choose Bind to Data in its context menu.

In the Bind to Data window, click Bind to an Object tab and then select URL string

--Hong

From Creator Team

Hong_Lua at 2007-7-9 23:09:03 > top of Java-index,Development Tools,Java Tools...
# 2
Thanks Hong_Lu :)This code is working fine.Best regards.
sotota at 2007-7-9 23:09:03 > top of Java-index,Development Tools,Java Tools...