Foren

Change default Model Hints Liferay 7

thumbnail
Arthur Marinho, geändert vor 7 Jahren.

Change default Model Hints Liferay 7

New Member Beiträge: 24 Beitrittsdatum: 13.01.15 Neueste Beiträge
Hello everyone

I need to change the default value from a model hint from Journal Article.

The hint concerns the expirationDate field from the Web Contents.
The default value is 1 year. The desired change is that the default value becomes 2 months.

I created a hook via Blade CLI and deployed it. As far as Liferay is concerned, the hook is deployed
and recognized (checked via Gogo Shell). That means, it should work. But the default value for the
expiration date is still 1 year.

Is it possible to hook Model hints in Liferay 7?
thumbnail
David H Nebinger, geändert vor 7 Jahren.

RE: Change default Model Hints Liferay 7

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
Model hints are only used when the DB is created to define the right column types and sizes.

Model hints have no impact on runtime function of the portal.




Come meet me at the NAS!
thumbnail
Arthur Marinho, geändert vor 7 Jahren.

RE: Change default Model Hints Liferay 7

New Member Beiträge: 24 Beitrittsdatum: 13.01.15 Neueste Beiträge
Hi David

Thanks for your answer.

I didn't know that. Then how can I change the default expiration date when creating a Web Content?

I did a research on the source code from Liferay and couldn't find any implementation that does this logic. Which is:
  • get today's date and add a year
thumbnail
David H Nebinger, geändert vor 7 Jahren.

RE: Change default Model Hints Liferay 7 (Antwort)

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
I stand corrected!

So actually in the /html/taglib/ui/input_field/page.jsp file for the <liferay-ui:input-field /> tag, which is in fact used by the <aui:input /> tag specifically pulled in from modules/apps/web-experience/journal/journal-web/src/main/resources/META-INF/resources/article/schedule.jsp for the expirationDate field of the journal article, you can see where model hints are going to play a part in defining a default expiration date that is one year ahead.

I found this code about year interesting:

			int year = -1;

			if (!ignoreRequestValue) {
				year = ParamUtil.getInteger(request, fieldParam + "Year", year);
			}

			if ((year == -1) &amp;&amp; (cal != null)) {
				year = cal.get(Calendar.YEAR);

				if (checkDefaultDelta &amp;&amp; (hints != null)) {
					int defaultYearDelta = GetterUtil.getInteger(hints.get("default-year-delta"));

					cal.add(Calendar.YEAR, defaultYearDelta);

					updateFromDefaultDelta = true;
				}
			}


Now to get towards what you want, I think you'd have to use a JSP override on schedule.jsp.

It appears that the only thing you really need to do is add the "defaultValue" attribute (with a valid date). This prevents the "checkDefaultDelta" stuff from kicking in and using the hints value.

In your JSP override, you can of course calculate a date that is 2 months in the future and all should be fine.






Come meet me at the NAS!
thumbnail
Arthur Marinho, geändert vor 7 Jahren.

RE: Change default Model Hints Liferay 7

New Member Beiträge: 24 Beitrittsdatum: 13.01.15 Neueste Beiträge
Thanks again David.

It worked emoticon

Good to know about this guy here : /html/taglib/ui/input_field/page.jsp, since it does important stuff.
Pranav Parmar, geändert vor 7 Jahren.

RE: Change default Model Hints Liferay 7

New Member Beiträge: 10 Beitrittsdatum: 27.07.16 Neueste Beiträge
can you provide solution for this ?

https://web.liferay.com/community/forums/-/message_boards/message/77383716