Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7501657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:36:47+00:00 2026-05-29T20:36:47+00:00

I have a model like this defined… public class Product{ private long timestamp; //

  • 0

I have a model like this defined…

public class Product{
  private long timestamp;
  // get/set follows...
}

The timestamp field is fine for the database, since I persist the data via JPA. However, in the JSP output, I don’t want to present the timestamp as long, I want to present it as a customized String. I would like to define the long/String conversion in a custom method.

I could convert the timestamp field to DateTime or something, but this is a general question – how is it possible to process model data without modifying the model itself, because it’s just for the view? I looked into Spring Conversion and Formatter SPIs, but that doesn’t seem to fit here (Formatter is mainly for user input, Conversion applies to the whole model and I just want to manipulate one field of the model).

I already thought of creating a new object just for the view, passing all the data from the database model and manipulate it there, but there must be a better solution…

EDIT

Some additonal code…here is my controller:

@RequestMapping(method=RequestMethod.GET, value="/")
public ModelAndView getAllProducts() {
    List<Product> products = daoReader.findAllProducts();

    ModelAndView mv = new ModelAndView("myproductview");
    mv.addObject("products", products);

    return mv;

And this is the JSP (simplified):

<c:forEach items="${products}" var="currentproduct">
        <tr>
            <td>${currentproduct.timestamp}</td>
            <td>${currentproduct.name}</td>
        </tr>
</c:forEach>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:36:49+00:00Added an answer on May 29, 2026 at 8:36 pm

    Spring views normally use getters and setters to access the data of a model. The best solution would be to provide a getter that formats the date or convert the long object to a Date object or some other required format. From the views, you then access this getter method.

    EDIT

    public class Product{
      private long timestamp;
    
      public Date getDate() {
            return new Date(timestamp);
      }
    }
    

    and from the view

    <c:forEach items="${products}" var="currentproduct">
            <tr>
                <td>${currentproduct.date}</td>
                <td>${currentproduct.name}</td>
            </tr>
    </c:forEach>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have defined a model like this: class Model extends Zend_Db_Table_Abstract { $_primary
I have a model defined like this: class UserDetail(models.Model): user = models.ForeignKey(User, db_index=True, unique=True,
I have a model class like this: namespace Models { public struct Localization {
I have a model that looks something like this: public class SampleModel { public
I have a before_save in my Message model defined like this: class Message <
I defined a model like this public class Planilla { [Key] public int IDPlanilla
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
Let's say I have a model like this class Foo(db.Model): id = db.StringProperty() bar
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.