Foren

RE: No luck working with multiple forms in the same portlet -Help Needed!

Alexander Widerberg, geändert vor 11 Jahren.

No luck working with multiple forms in the same portlet -Help Needed!

New Member Beiträge: 7 Beitrittsdatum: 14.04.12 Neueste Beiträge
Hi!

As the subject says i´m out of luck on this one...

Basically i just want to have multiple forms in the same portlet and then i want to be able to distinguish between them in the processAction, which one of them that has been submitted.
My first thought was to use a hidden field in each form and then, via that, be able to process the form in a working manner. I haven´t tested this out yet since i saw someone, somewhere pointing out that that wasn´t the right method of doing it.

I´m new to development in liferay.

The attached picture illustrates my scenario.

Can someone point me in the right direction or even submit an example? This would be much appreciated!

Thanks in advance!
Alexander
thumbnail
Sandeep Nair, geändert vor 11 Jahren.

RE: No luck working with multiple forms in the same portlet -Help Needed!

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
Can you please attach the jsp snippet of the page?
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: No luck working with multiple forms in the same portlet -Help Needed!

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
What do you mean, no luck? You can't really assist someone saying "no luck" when there's no detail explaining what is failing?

Normally each form would have it's own action url which results in taking different routes once it gets back to the server.

By the sounds of it you're trying to use the same action url for each of the forms (not what I'd do, but hey that's just me), in which case I think the hidden field is probably the way to go.
Alexander Widerberg, geändert vor 11 Jahren.

RE: No luck working with multiple forms in the same portlet -Help Needed!

New Member Beiträge: 7 Beitrittsdatum: 14.04.12 Neueste Beiträge
Yes im using the same actionURL for each form. With no luck i mean that i dont get it to work. This is of course due to the fact that i dont have the sufficient knowledge in liferay.

Anyway, in my case below the actionURL aint defined properly. I have looked at multiple examples and i know how to make calls via actionURL. I just don´t know how to make calls for multiple forms via actionURL on the same page and then using the same processAction method. This code don´t need to look finished since this is just going to be a prototype with basic functionality.

I have attatched the code for my forms below:
The following form will add Consumers to the database!
<form method="POST" action="<portlet:actionURL/>">
<table>
    <tbody><tr>
        <td>Name:</td>
        <td><input type="text" name="name"></td>
    </tr>
    <tr>
        <td><input type="submit" value="Send" title="Send"></td>
    </tr>
    </tbody></table>
</form>
<br>
The following form will add Vehicles to the database!
<form method="POST" action="<portlet:actionURL/>">
<table>
    <tbody><tr>
        <td>Name:</td>
        <td><input type="text" name="name"></td>
    </tr>
    <tr>
        <td><input type="submit" value="Send" title="Send"></td>
    </tr>
    </tbody></table>
</form>
<br>
The following form will add service-claims to the database!
<form method="POST" action="<portlet:actionURL/>">
<table>
    <tbody><tr>
        <td>Name:</td>
        <td><input type="text" name="name"></td>
    </tr>
    <tr>
        <td><input type="submit" value="Send" title="Send"></td>
    </tr>
    </tbody></table>
</form>
<br>
The following form will add warranty-claims to the database!
<form method="POST" action="<portlet:actionURL/>">
<table>
    <tbody><tr>
        <td>Name:</td>
        <td><input type="text" name="name"></td>
    </tr>
    <tr>
        <td><input type="submit" value="Send" title="Send"></td>
    </tr>
    </tbody></table>
</form>


So, my question is: How do i make the calls via actionURL for each form and how do i process them?

Thanks
Alexander
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: No luck working with multiple forms in the same portlet -Help Needed!

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
Why use separate forms?

If they're all going to the same action, just change the id fields so they are all unique, and you can determine which route to take in the action handler...

Lots of ways to do this better. A radio button for the type of action and then the input fields, ...

You're trying to bang a square peg into a round hole...
thumbnail
Sandeep Nair, geändert vor 11 Jahren.

RE: No luck working with multiple forms in the same portlet -Help Needed!

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
I agree with David. If you still have to use multiple forms use the following snippet

<form method="POST" action="<portlet:actionURL name='addConsumers' />">
<table>
    <tbody><tr>
        <td>Name:</td>
        <td><input type="text" name="name"></td>
    </tr>
    <tr>
        <td><input type="submit" value="Send" title="Send"></td>
    </tr>
    </tbody></table>
</form>
<br>
The following form will add Vehicles to the database!
<form method="POST" action="<portlet:actionURL name='addVehicles' />">
<table>
    <tbody><tr>
        <td>Name:</td>
        <td><input type="text" name="name"></td>
    </tr>
    <tr>
        <td><input type="submit" value="Send" title="Send"></td>
    </tr>
    </tbody></table>
</form>
<br>
The following form will add service-claims to the database!
<form method="POST" action="<portlet:actionURL name='addServiceClaims' />">
<table>
    <tbody><tr>
        <td>Name:</td>
        <td><input type="text" name="name"></td>
    </tr>
    <tr>
        <td><input type="submit" value="Send" title="Send"></td>
    </tr>
    </tbody></table>
</form>
<br>
The following form will add warranty-claims to the database!
<form method="POST" action="<portlet:actionURL name='addWarrantyClaims' />">
<table>
    <tbody><tr>
        <td>Name:</td>
        <td><input type="text" name="name"></td>
    </tr>
    <tr>
        <td><input type="submit" value="Send" title="Send"></td>
    </tr>
    </tbody></table>
</form>


And in your portlet class you will add something like the following assuming you are using MVCPortlet. You have to Remove processAction method while while applying the solution mentioned below. Make sure the name of the method is same as name in the actionURL

public void addConsumers(
            ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

        // Add code here to send an email
    }

public void addVehicles(
            ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

        // Add code here to send an email
    }

public void addWarrantyClaims(
            ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

        // Add code here to send an email
    }

public void addServiceClaims(
            ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

        // Add code here to send an email
    }


 public void addWarrantyClaims(
            ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

        // Add code here to send an email
    }


Now when someone submits form for adding vehicles the addVehicles method in the portlet should get called. (Once again reminding, this solution is for portlets extending MVCPortlet)
Alexander Widerberg, geändert vor 11 Jahren.

RE: No luck working with multiple forms in the same portlet -Help Needed!

New Member Beiträge: 7 Beitrittsdatum: 14.04.12 Neueste Beiträge
Thanks for your reply!

As of my implementation, the forms i use are much more sophisticated then my example above.
Sandeep, thanks for the code-snippet! I´ll try and see if i get it to work using MVCPortlet. As of now, i´m extending GenericPortlet.

Otherwise i´ll just go with different hidden fields (or the radio-button method mentioned above by David).
thumbnail
Sandeep Nair, geändert vor 11 Jahren.

RE: No luck working with multiple forms in the same portlet -Help Needed!

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
You have to use annotated method if you are using Generic portlet
For example your addConsumersmethod would be annotated like this

@ProcessAction(name="addConsumers")
public void addConsumers(
            ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

        // Add code here to send an email
    }


Same way you have to follow for other methods.

Regards,
Sandeep
Gautam Sharma, geändert vor 11 Jahren.

RE: No luck working with multiple forms in the same portlet -Help Needed!

Junior Member Beiträge: 92 Beitrittsdatum: 30.04.12 Neueste Beiträge
Hi Sandeep,

I have one from and multiple request so could please tell me how can i achieve it.
Have scenario but instead of having multiple forms i have only one form and multiple actions

Thanks in advance.
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: No luck working with multiple forms in the same portlet -Help Needed!

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
What's the problem (besides trying to revive an old thread)?

You define multiple action urls which map back to the action implementations in the back end.
Gautam Sharma, geändert vor 11 Jahren.

RE: No luck working with multiple forms in the same portlet -Help Needed!

Junior Member Beiträge: 92 Beitrittsdatum: 30.04.12 Neueste Beiträge
actually i am new to liferay so i was not aware of this....i will open new thread if i have any doubt henceforth.