java - How to keep logic out of a JSP? -


this question has answer here:

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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -