Announcement Announcement Module
Collapse
No announcement yet.
Trying to Manipulate objects returned from Service in a Controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trying to Manipulate objects returned from Service in a Controller

    So I have a simple controller returning a list of objects and putting them in a ModelMap

    Code:
    @Controller
    public class EventeController{
    
        protected final Log logger = LogFactory.getLog(getClass());
        
        @Autowired
        private EventService eventService;
           
        @RequestMapping("/listEvents.html")
        public ModelMap list(ModelMap model) {
    
        	model.put("eventModel", eventService.listEvent());
    				
    	logger.info("\nView all my objects .... \n");
    	return model;
    
    	}
    
    }

    What I would like to do is manipulate the data in one or more of the fields within my Event objects.

    Eg..

    The database returns with a long "dateStart = 2345673000000"
    the date is stored in milliseconds.

    What I'm looking to somehow do is take the "dateStart long" from my objects and convert them to a string. Then send them on to the view.

    Is there some way in the controller to do this? If I autowire in the event Domain object and call a getter on it?

    Or is there a way to manipulate data on a ModelMap?

    Code:
    Long dateStart = event.getDtStart();
    //then using the long I can change it to a date string
    I can do it the opposite way around. Take a date string and convert it to
    milliseconds and store it in the database. (I do this in the validation of the form)

    Code:
    //Using Joda Date/Time
    public class EventDateValidator {
    
    	public void validateDate(EventHomePage eventHomePage, String dtStartDate, String timeStart, 
    							String dtEndDate, String timeEnd, Errors errors) {
    		
    		String dtStartSt = dtStartDate + " " + timeStart;
    		String dtEndSt = dtEndDate + " " + timeEnd;
    		
    		DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy h:mm aa").withOffsetParsed();
    				
    		DateTime dts = formatter.parseDateTime(dtStartSt);
    		DateTime dte = formatter.parseDateTime(dtEndSt);
    		event.setDtStart(dts.getMillis());
    		event.setDtEnd(dte.getMillis());
    
    }
    So in conclusion I want to somehow edit data that was retrieved from the database in the controller!

    Thanks
Working...
X