Foros de discusión

aui:form with many aui:button

Oriol Mesia, modificado hace 11 años.

aui:form with many aui:button

Junior Member Mensajes: 64 Fecha de incorporación: 4/04/13 Mensajes recientes
Hi people,

I am trying to develop an aui:form with three aui:button this way...


<portlet:actionURL name="generateRule" var="generateRuleURL"/>
<portlet:actionURL name="generateRuleAnd" var="generateRuleAndURL"/>
<portlet:actionURL name="generateRuleOr" var="generateRuleOrURL"/>

<aui:form action="<%= generateRuleURL.toString() %>" method="post">
<aui:fieldset column="false">
<aui:select name="FirstRuleElement" >
<aui:option value="Age">
<liferay-ui:message key="Age" />
</aui:option>
<aui:option value="Country">
<liferay-ui:message key="Country" />
</aui:option>
<aui:option value="Direction">
<liferay-ui:message key="Direction" />
</aui:option>
</aui:select>
<aui:select name="FirstRuleAttribute" >
<aui:option value="Age">
<liferay-ui:message key="Age" />
</aui:option>
<aui:option value="Country">
<liferay-ui:message key="Country" />
</aui:option>
<aui:option value="Direction">
<liferay-ui:message key="Direction" />
</aui:option>
</aui:select>
</aui:fieldset>
<aui:fieldset column="false">
<aui:button-row>
<aui:button type="submit" value="End" />

<aui:button type="submit" value="And"
onClick="<%= generateRuleAndURL.toString()%>" />

<aui:button type="submit" value="Or"
onClick="<%= generateRuleOrURL.toString()%>" />
</aui:button-row>
</aui:fieldset>
</aui:form>

And I want to execute different methods from the Portlet, depending on the button pressed...

public void generateRule(ActionRequest request, ActionResponse response)
public void generateRuleAnd(ActionRequest request, ActionResponse response)
public void generateRuleOr(ActionRequest request, ActionResponse response)

But by doing click on the And and Or buttons I don't get the request parameters of the form.


Do you know how I can solve this??

Thank you,
Oriol
thumbnail
mohammad azaruddin, modificado hace 11 años.

RE: aui:form with many aui:button

Expert Mensajes: 492 Fecha de incorporación: 17/09/12 Mensajes recientes
Hi

i used something like this
<aui:form name="fm" method="post" action="<%=myActionURL.toString()%>">
<aui:button name="button1" type="submit" value="XXX" />
<aui:button name="button2" type="button" value=" YYY" href="<%=myRenderURL.toString()%>" />
</aui:form
>

So when i click on first button form is submitted and it will go to action URL.and when i click on second button render URL is executed.
I stil confused how if Threre are two action URL for single form..


If you get solution for this please post here


Azhar
Oriol Mesia, modificado hace 11 años.

RE: aui:form with many aui:button

Junior Member Mensajes: 64 Fecha de incorporación: 4/04/13 Mensajes recientes
System.out.println("Parameters : " + request.getParameter("FirstRuleElement"));
System.out.println("Parameters : " + request.getParameter("FirstRuleAttribute"));
System.out.println("Parameters : " + request.getParameter("Operator"));

Using that on the destiny method I get three nulls.


Thank you but your code doesn't function for me.
thumbnail
Anup Krishnan, modificado hace 11 años.

RE: aui:form with many aui:button

New Member Mensajes: 9 Fecha de incorporación: 14/04/11 Mensajes recientes
Hi,

The target method received the null values because the form was never submitted , intead it was just a url request using href link.

Just as Amit suggested , try to call a commont script when any of the button clicked, and let the script decide which url to call.

Try this :
Add an name to the form :
<aui:form action="<%= generateRuleURL.toString() %>" name="formToSubmit" method="post">

Change the current button type and onclicks as below :
<aui:button type="button" value="End" onClick="<%= commonFunction('End')%>" />
<aui:button type="button" value="And" onClick="<%= commonFunction('And')%>" />
<aui:button type="button" value="Or" onClick="<%= commonFunction('Or')%>" />

Add a javascript in your page:
<script>
function commonFunction(value){
// 1) validate the form
// 2) check for the val and depending on that change the action of the form
// eg. if(val=='Or') { AUI().one("#<portlet:namespace/>formToSubmit").action='<%= generateRuleOrURL.toString()%>';}
// 3) Submit the form
}
</script>


HTH
Anup
Oriol Mesia, modificado hace 10 años.

RE: aui:form with many aui:button

Junior Member Mensajes: 64 Fecha de incorporación: 4/04/13 Mensajes recientes
Anup Krishnan:
Hi,

The target method received the null values because the form was never submitted , intead it was just a url request using href link.

Just as Amit suggested , try to call a commont script when any of the button clicked, and let the script decide which url to call.

Try this :
Add an name to the form :
<aui:form action="<%= generateRuleURL.toString() %>" name="formToSubmit" method="post">

Change the current button type and onclicks as below :
<aui:button type="button" value="End" onClick="<%= commonFunction('End')%>" />
<aui:button type="button" value="And" onClick="<%= commonFunction('And')%>" />
<aui:button type="button" value="Or" onClick="<%= commonFunction('Or')%>" />

Add a javascript in your page:
<script>
function commonFunction(value){
// 1) validate the form
// 2) check for the val and depending on that change the action of the form
// eg. if(val=='Or') { AUI().one("#<portlet:namespace/>formToSubmit").action='<%= generateRuleOrURL.toString()%>';}
// 3) Submit the form
}
</script>


HTH
Anup


Hi, thank you for the help but now I'm getting an error that I could not understand...

line 97 en el archivo jsp: /view.jsp
Invalid character constant
94: <aui:fieldset column="false">
95: <aui:input cssClass="lfr-textarea-container" name="ruleDefinition" style="height: 75px; width: 100%;" type="textarea" value="" wrap="off" />
96: <aui:button-row>
97: <aui:button type="button" value="End" onClick="<%= commonFunction('End')%>" />
98: <aui:button type="button" value="And" onClick="<%= commonFunction('And')%>" />
99: <aui:button type="button" value="Or" onClick="<%= commonFunction('Or')%>" />
100: </aui:button-row>

And I placed the function in the same view.jsp file as follows:

<portlet:defineObjects />

<portlet:actionURL name="generateRule" var="generateRuleURL"/>
<portlet:actionURL name="generateRuleAnd" var="generateRuleAndURL"/>
<portlet:actionURL name="generateRuleOr" var="generateRuleOrURL"/>

<script>
function commonFunction(value){
// 1) validate the form
var x=document.forms["rulesForm"]["FirstRuleElement"].value;
System.out.println("Prova : " + x);
var y=document.forms["rulesForm"]["FirstRuleAttribute"].value;
System.out.println("Prova : " + y);
var z=document.forms["rulesForm"]["Operator"].value;
System.out.println("Prova : " + z);
alert("First name must be filled out");
if (x==null || x=="" || y==null || y=="" || z==null || z=="")
{
alert("First name must be filled out");
return false;
}
// 2) check for the val and depending on that change the action of the form
if(value=='Or') { AUI().one("#<portlet:namespace/>rulesForm").action='<%= generateRuleOrURL.toString()%>';}
if(value=='And') { AUI().one("#<portlet:namespace/>rulesForm").action='<%= generateRuleAndURL.toString()%>';}
if(value=='End') { AUI().one("#<portlet:namespace/>rulesForm").action='<%= generateRuleURL.toString()%>';}
// 3) Submit the form
document.forms["rulesForm"].submit();
}
</script>

<c:choose>
<c:when test="<%= themeDisplay.isSignedIn() %>">
<aui:form action="<%= generateRuleURL.toString() %>" name="rulesForm" method="post">


.....

Could you help me with that, please? Thank you in advance!
thumbnail
Anup Krishnan, modificado hace 10 años.

RE: aui:form with many aui:button

New Member Mensajes: 9 Fecha de incorporación: 14/04/11 Mensajes recientes
Sorry my mistake it should be :
<aui:button type="button" value="End" onClick="commonFunction('End')" />
<aui:button type="button" value="And" onClick="commonFunction('And')" />
<aui:button type="button" value="Or" onClick="commonFunction('Or')" />

HTH
Anup
thumbnail
Amit Doshi, modificado hace 11 años.

RE: aui:form with many aui:button

Liferay Master Mensajes: 550 Fecha de incorporación: 29/12/10 Mensajes recientes
Oriol Mesia:
Hi people,

I am trying to develop an aui:form with three aui:button this way...


<portlet:actionURL name="generateRule" var="generateRuleURL"/>
<portlet:actionURL name="generateRuleAnd" var="generateRuleAndURL"/>
<portlet:actionURL name="generateRuleOr" var="generateRuleOrURL"/>

<aui:form action="<%= generateRuleURL.toString() %>" method="post">
<aui:fieldset column="false">
<aui:select name="FirstRuleElement" >
<aui:option value="Age">
<liferay-ui:message key="Age" />
</aui:option>
<aui:option value="Country">
<liferay-ui:message key="Country" />
</aui:option>
<aui:option value="Direction">
<liferay-ui:message key="Direction" />
</aui:option>
</aui:select>
<aui:select name="FirstRuleAttribute" >
<aui:option value="Age">
<liferay-ui:message key="Age" />
</aui:option>
<aui:option value="Country">
<liferay-ui:message key="Country" />
</aui:option>
<aui:option value="Direction">
<liferay-ui:message key="Direction" />
</aui:option>
</aui:select>
</aui:fieldset>
<aui:fieldset column="false">
<aui:button-row>
<aui:button type="submit" value="End" />

<aui:button type="submit" value="And"
onClick="<%= generateRuleAndURL.toString()%>" />

<aui:button type="submit" value="Or"
onClick="<%= generateRuleOrURL.toString()%>" />
</aui:button-row>
</aui:fieldset>
</aui:form>

And I want to execute different methods from the Portlet, depending on the button pressed...

public void generateRule(ActionRequest request, ActionResponse response)
public void generateRuleAnd(ActionRequest request, ActionResponse response)
public void generateRuleOr(ActionRequest request, ActionResponse response)

But by doing click on the And and Or buttons I don't get the request parameters of the form.


Do you know how I can solve this??

Thank you,
Oriol


Rather than making all button as submit. Make all of them as type="button" and bind the click event on the button. And based on the click call the AUI Script or javascript and call the url respectively from the Script.

Thanks & Regards,
Amit Doshi
thumbnail
mohammad azaruddin, modificado hace 11 años.

RE: aui:form with many aui:button

Expert Mensajes: 492 Fecha de incorporación: 17/09/12 Mensajes recientes
HI amith
what you suggested is almost clear and there will be no action attribute in aui:form tag.'m i correct...?
thumbnail
Amit Doshi, modificado hace 10 años.

RE: aui:form with many aui:button

Liferay Master Mensajes: 550 Fecha de incorporación: 29/12/10 Mensajes recientes
mohammad azaruddin:
HI amith
what you suggested is almost clear and there will be no action attribute in aui:form tag.'m i correct...?


There is an attribute action available in aui:form but you don't require the same in your current requirement.
thumbnail
mohammad azaruddin, modificado hace 10 años.

RE: aui:form with many aui:button

Expert Mensajes: 492 Fecha de incorporación: 17/09/12 Mensajes recientes
HI amith

Thank you emoticon