Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
Alexander Widerberg
No luck working with multiple forms in the same portlet -Help Needed!
16 aprile 2012 6.31
Risposta

Alexander Widerberg

Punteggio: New Member

Messaggi: 7

Data di Iscrizione: 14 aprile 2012

Messaggi recenti

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
Allegato

Allegati: multiple_forms.JPG (24,7k)
Sandeep Nair
RE: No luck working with multiple forms in the same portlet -Help Needed!
16 aprile 2012 6.37
Risposta

Sandeep Nair

Punteggio: Liferay Legend

Messaggi: 1692

Data di Iscrizione: 5 novembre 2008

Messaggi recenti

Can you please attach the jsp snippet of the page?
David H Nebinger
RE: No luck working with multiple forms in the same portlet -Help Needed!
16 aprile 2012 6.42
Risposta

David H Nebinger

Punteggio: Liferay Legend

Messaggi: 7004

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
RE: No luck working with multiple forms in the same portlet -Help Needed!
16 aprile 2012 7.42
Risposta

Alexander Widerberg

Punteggio: New Member

Messaggi: 7

Data di Iscrizione: 14 aprile 2012

Messaggi recenti

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:
 1The following form will add Consumers to the database!
 2<form method="POST" action="<portlet:actionURL/>">
 3<table>
 4    <tr>
 5        <td>Name:</td>
 6        <td><Input type="text" name="name"/></td>
 7    </tr>
 8    <tr>
 9        <td><Input type="submit" value="Send" title="Send"/></td>
10    </tr>
11    </table>
12</form>
13<br>
14The following form will add Vehicles to the database!
15<form method="POST" action="<portlet:actionURL/>">
16<table>
17    <tr>
18        <td>Name:</td>
19        <td><Input type="text" name="name"/></td>
20    </tr>
21    <tr>
22        <td><Input type="submit" value="Send" title="Send"/></td>
23    </tr>
24    </table>
25</form>
26<br>
27The following form will add service-claims to the database!
28<form method="POST" action="<portlet:actionURL/>">
29<table>
30    <tr>
31        <td>Name:</td>
32        <td><Input type="text" name="name"/></td>
33    </tr>
34    <tr>
35        <td><Input type="submit" value="Send" title="Send"/></td>
36    </tr>
37    </table>
38</form>
39<br>
40The following form will add warranty-claims to the database!
41<form method="POST" action="<portlet:actionURL/>">
42<table>
43    <tr>
44        <td>Name:</td>
45        <td><Input type="text" name="name"/></td>
46    </tr>
47    <tr>
48        <td><Input type="submit" value="Send" title="Send"/></td>
49    </tr>
50    </table>
51</form>


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

Thanks
Alexander
David H Nebinger
RE: No luck working with multiple forms in the same portlet -Help Needed!
16 aprile 2012 9.32
Risposta

David H Nebinger

Punteggio: Liferay Legend

Messaggi: 7004

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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...
Sandeep Nair
RE: No luck working with multiple forms in the same portlet -Help Needed!
16 aprile 2012 22.09
Risposta

Sandeep Nair

Punteggio: Liferay Legend

Messaggi: 1692

Data di Iscrizione: 5 novembre 2008

Messaggi recenti

I agree with David. If you still have to use multiple forms use the following snippet

 1<form method="POST" action="<portlet:actionURL name='addConsumers' />">
 2<table>
 3    <tr>
 4        <td>Name:</td>
 5        <td><Input type="text" name="name"/></td>
 6    </tr>
 7    <tr>
 8        <td><Input type="submit" value="Send" title="Send"/></td>
 9    </tr>
10    </table>
11</form>
12<br>
13The following form will add Vehicles to the database!
14<form method="POST" action="<portlet:actionURL name='addVehicles' />">
15<table>
16    <tr>
17        <td>Name:</td>
18        <td><Input type="text" name="name"/></td>
19    </tr>
20    <tr>
21        <td><Input type="submit" value="Send" title="Send"/></td>
22    </tr>
23    </table>
24</form>
25<br>
26The following form will add service-claims to the database!
27<form method="POST" action="<portlet:actionURL name='addServiceClaims' />">
28<table>
29    <tr>
30        <td>Name:</td>
31        <td><Input type="text" name="name"/></td>
32    </tr>
33    <tr>
34        <td><Input type="submit" value="Send" title="Send"/></td>
35    </tr>
36    </table>
37</form>
38<br>
39The following form will add warranty-claims to the database!
40<form method="POST" action="<portlet:actionURL name='addWarrantyClaims' />">
41<table>
42    <tr>
43        <td>Name:</td>
44        <td><Input type="text" name="name"/></td>
45    </tr>
46    <tr>
47        <td><Input type="submit" value="Send" title="Send"/></td>
48    </tr>
49    </table>
50</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

 1public void addConsumers(
 2            ActionRequest actionRequest, ActionResponse actionResponse)
 3        throws IOException, PortletException {
 4
 5        // Add code here to send an email
 6    }
 7
 8public void addVehicles(
 9            ActionRequest actionRequest, ActionResponse actionResponse)
10        throws IOException, PortletException {
11
12        // Add code here to send an email
13    }
14
15public void addWarrantyClaims(
16            ActionRequest actionRequest, ActionResponse actionResponse)
17        throws IOException, PortletException {
18
19        // Add code here to send an email
20    }
21
22public void addServiceClaims(
23            ActionRequest actionRequest, ActionResponse actionResponse)
24        throws IOException, PortletException {
25
26        // Add code here to send an email
27    }
28
29
30 public void addWarrantyClaims(
31            ActionRequest actionRequest, ActionResponse actionResponse)
32        throws IOException, PortletException {
33
34        // Add code here to send an email
35    }


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
RE: No luck working with multiple forms in the same portlet -Help Needed!
17 aprile 2012 1.11
Risposta

Alexander Widerberg

Punteggio: New Member

Messaggi: 7

Data di Iscrizione: 14 aprile 2012

Messaggi recenti

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).
Sandeep Nair
RE: No luck working with multiple forms in the same portlet -Help Needed!
17 aprile 2012 1.41
Risposta

Sandeep Nair

Punteggio: Liferay Legend

Messaggi: 1692

Data di Iscrizione: 5 novembre 2008

Messaggi recenti

You have to use annotated method if you are using Generic portlet
For example your addConsumersmethod would be annotated like this

1@ProcessAction(name="addConsumers")
2public void addConsumers(
3            ActionRequest actionRequest, ActionResponse actionResponse)
4        throws IOException, PortletException {
5
6        // Add code here to send an email
7    }


Same way you have to follow for other methods.

Regards,
Sandeep
Gautam Sharma
RE: No luck working with multiple forms in the same portlet -Help Needed!
30 aprile 2012 7.41
Risposta

Gautam Sharma

Punteggio: Junior Member

Messaggi: 59

Data di Iscrizione: 30 aprile 2012

Messaggi recenti

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.
David H Nebinger
RE: No luck working with multiple forms in the same portlet -Help Needed!
30 aprile 2012 9.08
Risposta

David H Nebinger

Punteggio: Liferay Legend

Messaggi: 7004

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
RE: No luck working with multiple forms in the same portlet -Help Needed!
3 maggio 2012 1.00
Risposta

Gautam Sharma

Punteggio: Junior Member

Messaggi: 59

Data di Iscrizione: 30 aprile 2012

Messaggi recenti

actually i am new to liferay so i was not aware of this....i will open new thread if i have any doubt henceforth.