Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Oriol Mesia
aui:form with many aui:button
24 aprile 2013 1.50
Risposta

Oriol Mesia

Punteggio: Junior Member

Messaggi: 64

Data di Iscrizione: 4 aprile 2013

Messaggi recenti

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
Mohammad Azharuddin
RE: aui:form with many aui:button
24 aprile 2013 7.24
Risposta

Mohammad Azharuddin

Punteggio: Expert

Messaggi: 471

Data di Iscrizione: 17 settembre 2012

Messaggi recenti

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
Amit Doshi
RE: aui:form with many aui:button
25 aprile 2013 0.39
Risposta

Amit Doshi

Punteggio: Liferay Master

Messaggi: 549

Data di Iscrizione: 29 dicembre 2010

Messaggi recenti

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
Oriol Mesia
RE: aui:form with many aui:button
26 aprile 2013 0.41
Risposta

Oriol Mesia

Punteggio: Junior Member

Messaggi: 64

Data di Iscrizione: 4 aprile 2013

Messaggi recenti

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.
Anup Krishnan
RE: aui:form with many aui:button
26 aprile 2013 1.35
Risposta

Anup Krishnan

Punteggio: New Member

Messaggi: 9

Data di Iscrizione: 14 aprile 2011

Messaggi recenti

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
Mohammad Azharuddin
RE: aui:form with many aui:button
26 aprile 2013 1.51
Risposta

Mohammad Azharuddin

Punteggio: Expert

Messaggi: 471

Data di Iscrizione: 17 settembre 2012

Messaggi recenti

HI amith
what you suggested is almost clear and there will be no action attribute in aui:form tag.'m i correct...?
Oriol Mesia
RE: aui:form with many aui:button
29 aprile 2013 1.19
Risposta

Oriol Mesia

Punteggio: Junior Member

Messaggi: 64

Data di Iscrizione: 4 aprile 2013

Messaggi recenti

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!
Anup Krishnan
RE: aui:form with many aui:button
2 maggio 2013 1.33
Risposta

Anup Krishnan

Punteggio: New Member

Messaggi: 9

Data di Iscrizione: 14 aprile 2011

Messaggi recenti

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
Amit Doshi
RE: aui:form with many aui:button
7 maggio 2013 4.40
Risposta

Amit Doshi

Punteggio: Liferay Master

Messaggi: 549

Data di Iscrizione: 29 dicembre 2010

Messaggi recenti

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.
Mohammad Azharuddin
RE: aui:form with many aui:button
7 maggio 2013 5.58
Risposta

Mohammad Azharuddin

Punteggio: Expert

Messaggi: 471

Data di Iscrizione: 17 settembre 2012

Messaggi recenti

HI amith

Thank you emoticon