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
How to change submit action of a form created by content
Hello, everyone!
I need to use a form I create in the portal. However, I need to save all the information on a new table and not de ddm tables created by default. I have try to use aui in a new module but the form doesn't have that beautiful css of the default forms from liferay portal.
Could somebody guide me, so that I can change the submit action.
Thank you!
I need to use a form I create in the portal. However, I need to save all the information on a new table and not de ddm tables created by default. I have try to use aui in a new module but the form doesn't have that beautiful css of the default forms from liferay portal.
Could somebody guide me, so that I can change the submit action.
Thank you!
Hi Viviana,
Good question. Looking at the plumbing for this portlet you can see that the action gets routed to the DDLFormPortlet. The view.jsp that renders the portlet sets the action like so --
In the new world of Liferay 7, these things are tied to Command classes, so if you dig through the source a little more, you will find that there is a class AddRecordMVCActionCommand (https://github.com/liferay/liferay-portal/blob/master/modules/apps/forms-and-workflow/dynamic-data-lists/dynamic-data-lists-form-web/src/main/java/com/liferay/dynamic/data/lists/form/web/internal/portlet/action/AddRecordMVCActionCommand.java)
You should be able to use a command override to provide the definition for the action as you want it to be performed (https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/overriding-mvc-commands)
.. just be aware that when you override this class, you end up overriding it across the board, for all forms. So You should include something in your logic that can detect that you you only want to override a certain form type. Maybe an override that allow you to set a portlet preference or a configuration option or something. If you detect the setting, then you can run your logic, otherwise, use the original action you are overriding.
Good question. Looking at the plumbing for this portlet you can see that the action gets routed to the DDLFormPortlet. The view.jsp that renders the portlet sets the action like so --
<portlet:actionurl name="addRecord" var="addRecordActionURL" />In the new world of Liferay 7, these things are tied to Command classes, so if you dig through the source a little more, you will find that there is a class AddRecordMVCActionCommand (https://github.com/liferay/liferay-portal/blob/master/modules/apps/forms-and-workflow/dynamic-data-lists/dynamic-data-lists-form-web/src/main/java/com/liferay/dynamic/data/lists/form/web/internal/portlet/action/AddRecordMVCActionCommand.java)
You should be able to use a command override to provide the definition for the action as you want it to be performed (https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/overriding-mvc-commands)
.. just be aware that when you override this class, you end up overriding it across the board, for all forms. So You should include something in your logic that can detect that you you only want to override a certain form type. Maybe an override that allow you to set a portlet preference or a configuration option or something. If you detect the setting, then you can run your logic, otherwise, use the original action you are overriding.
Is there a simple and complete example for overriding MVCActionCommands? I´m very new at developing Liferay.
That tutorial should be all you need -- it's pretty straight forward.
1. Create a module
2. Create a class
3. Configure the component
4. Add your @References
5. Add your logic
6. Deploy.
.. if you want to get it started and then share your code with me, I could help you along (if you get stuck)
1. Create a module
2. Create a class
3. Configure the component
4. Add your @References
5. Add your logic
6. Deploy.
.. if you want to get it started and then share your code with me, I could help you along (if you get stuck)
What type of template I should use to create that module?
I would start with the service template. That will get you the basics of what you need to get going. The service you are overriding is a MVCActionCommand -- the override itself is specified in the component properties (refer to that tutorial I sent yesterday)
How can I add on gradle the dependencies to use BlogsPortletKeys.BLOGS_ADMIN, I am trying to reproduce the tutorial you send me. And for the case of DDLFormPortletKeys.DYNAMIC_DATA_LISTS_FORM, which one would be.
Thank you, again.
Thank you, again.
Hello guys! I'm working in a similar problem. Did you find a solution for this problem? If so, could you please post the code?Thanks in advance
Hi Luiz, Did you try following the links that I posted above?
Hi Andrew! Yes, I followed What I tried to do was somethink like:
Actually, I think somethink related to
Do you have any idea in what could be wrong?
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import org.osgi.service.component.annotations.Component;import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;;@Component(
immediate = true,
property = {
"javax.portlet.name=_com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet_INSTANCE_TzUgftgM7rEm_fm",
"mvc.command.name=_com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet_INSTANCE_TzUgftgM7rEm_fm",
"service.ranking:Integer=100"
},
service = MVCActionCommand.class
)
public class HandlerForms extends BaseMVCActionCommand { @Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
// TODO Auto-generated method stub
System.out.println("Foo");
}}But didn't succeeded javax.portlet.name and mvc.command.name could be wrong - but already tried a bunch of different values but none of them worked. I followed something similar in this thread too but no success - https://liferay.dev/forums/-/message_boards/message/76707068.Do you have any idea in what could be wrong?
Don't include the instance name -- you can't actually override the command for a particular instance. You should just specify the portlet name (id)
com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet
.. and yeah, your command name is definitely not write. What action are you trying to override?
com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet
.. and yeah, your command name is definitely not write. What action are you trying to override?
Thanks! Finally is now working o/ Here is the working code:
@Component(
immediate = true,
property = {
"javax.portlet.name=com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet",
"mvc.command.name=addFormInstanceRecord",
"service.ranking:Integer=100"
},
service = MVCActionCommand.class
)
public class SCDigitalHandlerForms extends BaseMVCActionCommand { @Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
System.out.println("Foo");
}
}
Another thing I've got stuck: how to access the proper label and values from the forms? Anyone can help?I tried something like:
@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
String teste = actionResponse.getProperty("FIELD_NAME"); // Always return NULL
String teste2 = ParamUtil.getString(actionRequest, "FIELD_NAME"); // Always return NULL
}It's gonna be great if I could some object with all label and values directly. Is there any way to get that?Thanks again.
Can you show us the code from your JSP where the form fields are? (I want to make sure that you are using aui:input fields, and not just regular <input/> fields)
I'm not using JSP form - I'm using the form created in the portal.
Oh -- right, duh.
In that case, can you show me the markup (from the browser) for the form?
I was thinking more that you copy and paste the code out of the inspector into here, rather than a screenshot. I just wanted to see what the markup rendered -- more specifically to make sure that the namespace was part of the name attributes for the individual form elements. It looks ok -- can you show me the markup for just that "test" input field?
Here we go:
<input class="field form-control" dir="ltr" id="_com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet_INSTANCE_TzUgftgM7rEm_ddm$$test$3F2FKZmA$0$$en_US" name="_com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet_INSTANCE_TzUgftgM7rEm_ddm$$test$3F2FKZmA$0$$en_US" placeholder="" type="text" value="">
<input class="field form-control" dir="ltr" id="_com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet_INSTANCE_TzUgftgM7rEm_ddm$$test$3F2FKZmA$0$$en_US" name="_com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet_INSTANCE_TzUgftgM7rEm_ddm$$test$3F2FKZmA$0$$en_US" placeholder="" type="text" value="">
Awesome. Ok so that explains why your ParamUtil call is not working. You don't need to add the namespace because Liferay will manage that magic for you of course, but in your case, the field is not "test" but rather "$$test$3F2FKZmA$0$$en_US".. what I am wondering is if there is another field, a hidden one perhaps, on the form with the 3F2FKZmA$0 value in it. I am also curious, if you add ANOTHER field to the form, does it have the same postfix of $3F2FKZmA$0$$en_US added to the name?