I need to build a table in a JSP. I have an arraylist with a bunch of beans, and the beans were made from a resultset, just from the rows returned from a DB call.
Depending on the data, I want to show different things. An example would be, if the name in the bean starts with 'a', highlight the name, if it starts with 'b', make the name red but not highlighted (i think that covers my question/situation).
If I do not have logic in the JSP, how would I control this?
One way to do this is to write a function that lives inside the bean class, or perhaps more properly inside a wrapper for the bean class:
public class BeanFormatter {
private Bean bean;
public BeanFormatter(Bean myDataBean) {
this.bean = myDataBean;
}
public String getFormattedHTML() {
//put your logic here. Return the necessary HTML based on the bean.
}
}
It's possible that what you want to return is not HTML in format of a String, but a div name or other css class to wrap the data in. But you could just write another method such as getDisplayCSSClass()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With