Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Model Attribute in Spring MVC & Liferay MVC
Hi All,I m using Liferay DXP.
In Liferay MVC, Is there any way to fetch all the form fields in controller as a single object same as using Model Attribute in Spring MVC ?I am using aui:modelContext in the jsp to prepopulate already.
Thanks in Advance.
Regards,
Aravinth
In Liferay MVC, Is there any way to fetch all the form fields in controller as a single object same as using Model Attribute in Spring MVC ?I am using aui:modelContext in the jsp to prepopulate already.
Thanks in Advance.
Regards,
Aravinth
Hi,
You can use ServiceContext Object as single object for all your form fields, You can fetch your form field
You can use ServiceContext Object as single object for all your form fields, You can fetch your form field
ServiceContext serviceContext = null;
try {
serviceContext = ServiceContextFactory.getInstance(renderRequest);
} catch (PortalException e) {
_log.error(e);
}
serviceContext.getAttribute(formField);
Hi Yasin,Thanks for your reply. I don't want to set the values to object manually. Hope serviceContext way will make us to fetch the form values and set it to the object manually. Kindly share any sample code if you have.
Hi,
ServiceContext will not build/generate model object , but will provided single object from where all form values can be fetched as attributes .For generating model object may be you can use a model constructor with service context as parameter where it will generate object for you .
ServiceContext will not build/generate model object , but will provided single object from where all form values can be fetched as attributes .For generating model object may be you can use a model constructor with service context as parameter where it will generate object for you .
class xyz {
private long field1;
public modelConstructor(ServiceContext serviceContext) {
this.field1 = GetterUtil.getLong(serviceContext.getAttribute("formField1"));
}
}
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™