java - Design issue - sort array in controller or view? -


i developing mvc based application. have array contains names of clients. array populated database.

the controller (java) passes array view (jsp) , view renders it. list of clients needs displayed in ascending order. also, if there client called xyz, xyz client should displayed first in list. there other such rules.

the question is, from design perspective, should sorting happen? should happen in controller (java) or in view (jsp)?

as aside note, need mention more comfortable programming in java in jsp/javascript. if there no "right" or "wrong" way of doing it, prefer sorting in controller itself.

also, performance perspective, better?

from design perspective, controller should control rules of sorting, should not performing sorting itself. rather, should delegate task model. in ideal world, controller should not make modifications data, tell model how wants data modified.

unfortunately, reality interferes ideal designs: when users allowed control sorting, example clicking column headers, shortcut allows view sort data taken reduce number of roundtrips model (which implemented database) offloading rdbms. unfortunate side effect of decision lack of consistency paging: sorting in view orders data on current page, ignoring data in other pages should come before or after what's displayed. shortcoming presented users "feature".

in case, ordering appears part of "business rules": fact "xyz" record must remain on top, , there "other such rules" suggests sorting not purely visual concern. consider designing "sort descriptor" of kind can hold "metadata" sort. controller should create instance of "sort descriptor", , pass model processing. model should "interpret" content of descriptor, , produce data in correct order.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -