Process content data

Hello, I am trying to process documents fields before feeding the results to page model api. For example, let’s say I have a class NewsDocument for which I have the getters and setters

1. class NewsDocument extends BaseDocument{
2. private String title;
3. public String getTitle(){
4. if(title !=null{
5. return title;
6. }
7. return getProperty(“mynamespace:title”);
8. }
** public void setTitle(String value){**
9. title = value;
10. }
11. }

and in my component I get an object of that document and try to process data

1. NewsDocument document = …
2. String newTitle = document.getTitle().replaceAll(“foo”,“bar”);
3. document.setTitle(newTitle)…

The ideal case would be to actually return the title, but I am always getting null . The only way of getting documents fields so far is by creating in my component class a HippoBean object on which I am fetching a child HippoBean with the relative path:
HippoBean bean1 = request.getRequestContext().getSiteContentBaseBean().getBean(articleHeader.getArticleHeaderDocument());

Then, using bean1.getProperties() I am able to retrieve the entire properties for that particular document used.

My question is, what can I do to retrieve those properties using the first way ? Am I missing a step ?
Thank you


I don’t have a good answer for you on this as of yet. This behavior isn’t as I expected so I looked into it and I can at least confirm I see the same behavior.

As a workaround, I think it should be possible that you create a new object from the NewsDocument and set the values there as you like. you can then pass that object to the frontend.

OTOH, is there a reason to manipulate the values like this in the component rather than setting them as you want them on the document itself?

Hi Jasper,
Thank you for your response. Yes, I needed to format my date field in a different way . I am still unable to fix this behavior, but I kept doing it using the workaround provided

So the answer to your problem above is that that seems to be intended behavior. Objects are only serialized once, so it may not be your object that you set that you see, but another instance.

However, I would suggest you not manipulate your date in the component at all. The date as set is a standard ISO format in the repository. You should take care of formatting this on the frontend. There is very likely a frontend component/function included in whatever framework you use that can do this for you.