java - How to keep logic out of a JSP? -
this question has answer here:
- how avoid java code in jsp files? 26 answers
i need build table in jsp. have arraylist bunch of beans, , beans made resultset, rows returned db call.
depending on data, want show different things. example be, if name in bean starts 'a', highlight name, if starts 'b', make name red not highlighted (i think covers question/situation).
if not have logic in jsp, how control this?
one way write function lives inside bean class, or perhaps more inside wrapper bean class:
public class beanformatter { private bean bean; public beanformatter(bean mydatabean) { this.bean = mydatabean; } public string getformattedhtml() { //put logic here. return necessary html based on bean. } } it's possible want return not html in format of string, div name or other css class wrap data in. write method such getdisplaycssclass().
Comments
Post a Comment