Foros de discusión

How to change submit action of a form created by content

thumbnail
Viviana Salcedo, modificado hace 6 años.

How to change submit action of a form created by content

New Member Mensajes: 10 Fecha de incorporación: 25/09/17 Mensajes recientes
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!
thumbnail
Andrew Jardine, modificado hace 6 años.

RE: How to change submit action of a form created by content

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
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 --

<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.
thumbnail
Viviana Salcedo, modificado hace 6 años.

RE: How to change submit action of a form created by content

New Member Mensajes: 10 Fecha de incorporación: 25/09/17 Mensajes recientes
Is there a simple and complete example for overriding MVCActionCommands? I´m very new at developing Liferay.
thumbnail
Andrew Jardine, modificado hace 6 años.

RE: How to change submit action of a form created by content

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
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)
thumbnail
Viviana Salcedo, modificado hace 6 años.

RE: How to change submit action of a form created by content

New Member Mensajes: 10 Fecha de incorporación: 25/09/17 Mensajes recientes
What type of template I should use to create that module?
thumbnail
Andrew Jardine, modificado hace 6 años.

RE: How to change submit action of a form created by content

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
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)
thumbnail
Viviana Salcedo, modificado hace 6 años.

RE: How to change submit action of a form created by content

New Member Mensajes: 10 Fecha de incorporación: 25/09/17 Mensajes recientes
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.
Luiz Henrique Salazar, modificado hace 4 años.

RE: How to change submit action of a form created by content

New Member Mensajes: 10 Fecha de incorporación: 17/12/19 Mensajes recientes
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 emoticon
thumbnail
Andrew Jardine, modificado hace 4 años.

RE: How to change submit action of a form created by content

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Hi Luiz, Did you try following the links that I posted above?
Luiz Henrique Salazar, modificado hace 4 años.

RE: How to change submit action of a form created by content

New Member Mensajes: 10 Fecha de incorporación: 17/12/19 Mensajes recientes
Hi Andrew! Yes, I followed What I tried to do was somethink like:
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(
&nbsp; &nbsp; immediate = true,
&nbsp; &nbsp; property = {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"javax.portlet.name=_com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet_INSTANCE_TzUgftgM7rEm_fm",
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"mvc.command.name=_com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet_INSTANCE_TzUgftgM7rEm_fm",
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"service.ranking:Integer=100"
&nbsp; &nbsp; },
&nbsp; &nbsp; service = MVCActionCommand.class
)
public class HandlerForms extends BaseMVCActionCommand {
&nbsp;&nbsp; &nbsp;@Override
&nbsp;&nbsp; &nbsp;protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// TODO Auto-generated method stub
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("Foo");
&nbsp;&nbsp; &nbsp;}}

But didn't succeeded emoticon Actually, I think somethink related to 
javax.portlet.name 
and
&nbsp;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?
thumbnail
Andrew Jardine, modificado hace 4 años.

RE: How to change submit action of a form created by content

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
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?
Luiz Henrique Salazar, modificado hace 4 años.

RE: How to change submit action of a form created by content

New Member Mensajes: 10 Fecha de incorporación: 17/12/19 Mensajes recientes
Thanks! Finally is now working o/ Here is the working code:
@Component(
&nbsp; &nbsp; immediate = true,
&nbsp; &nbsp; property = {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"javax.portlet.name=com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet",
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"mvc.command.name=addFormInstanceRecord",
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"service.ranking:Integer=100"
&nbsp; &nbsp; },
&nbsp; &nbsp; service = MVCActionCommand.class
)
public class SCDigitalHandlerForms extends BaseMVCActionCommand {
&nbsp;&nbsp; &nbsp;@Override
&nbsp;&nbsp; &nbsp;protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("Foo");
&nbsp;&nbsp; &nbsp;}
}
Luiz Henrique Salazar, modificado hace 4 años.

RE: How to change submit action of a form created by content

New Member Mensajes: 10 Fecha de incorporación: 17/12/19 Mensajes recientes
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
&nbsp;&nbsp; &nbsp;protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;String teste = actionResponse.getProperty("FIELD_NAME");&nbsp;// Always return NULL
​​​​​​​&nbsp; &nbsp; &nbsp; &nbsp; 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.
thumbnail
Andrew Jardine, modificado hace 4 años.

RE: How to change submit action of a form created by content

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
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)
Luiz Henrique Salazar, modificado hace 4 años.

RE: How to change submit action of a form created by content

New Member Mensajes: 10 Fecha de incorporación: 17/12/19 Mensajes recientes
I'm not using JSP form - I'm using the form created in the portal.
thumbnail
Andrew Jardine, modificado hace 4 años.

RE: How to change submit action of a form created by content

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Oh -- right, duh. emoticon In that case, can you show me the markup (from the browser) for the form?
Luiz Henrique Salazar, modificado hace 4 años.

RE: How to change submit action of a form created by content

New Member Mensajes: 10 Fecha de incorporación: 17/12/19 Mensajes recientes
Do you mean this?
thumbnail
Andrew Jardine, modificado hace 4 años.

RE: How to change submit action of a form created by content

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
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?
Luiz Henrique Salazar, modificado hace 4 años.

RE: How to change submit action of a form created by content

New Member Mensajes: 10 Fecha de incorporación: 17/12/19 Mensajes recientes
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="">
thumbnail
Andrew Jardine, modificado hace 4 años.

RE: How to change submit action of a form created by content

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
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?