フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Oriol Mesia
aui:form with many aui:button
2013/04/24 1:50
答え

Oriol Mesia

ランク: Junior Member

投稿: 64

参加年月日: 2013/04/04

最近の投稿

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
2013/04/24 7:24
答え

Mohammad Azharuddin

ランク: Expert

投稿: 471

参加年月日: 2012/09/17

最近の投稿

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
2013/04/25 0:39
答え

Amit Doshi

ランク: Liferay Master

投稿: 549

参加年月日: 2010/12/29

最近の投稿

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
2013/04/26 0:41
答え

Oriol Mesia

ランク: Junior Member

投稿: 64

参加年月日: 2013/04/04

最近の投稿

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
2013/04/26 1:35
答え

Anup Krishnan

ランク: New Member

投稿: 9

参加年月日: 2011/04/14

最近の投稿

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
2013/04/26 1:51
答え

Mohammad Azharuddin

ランク: Expert

投稿: 471

参加年月日: 2012/09/17

最近の投稿

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
2013/04/29 1:19
答え

Oriol Mesia

ランク: Junior Member

投稿: 64

参加年月日: 2013/04/04

最近の投稿

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
2013/05/02 1:33
答え

Anup Krishnan

ランク: New Member

投稿: 9

参加年月日: 2011/04/14

最近の投稿

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
2013/05/07 4:40
答え

Amit Doshi

ランク: Liferay Master

投稿: 549

参加年月日: 2010/12/29

最近の投稿

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
2013/05/07 5:58
答え

Mohammad Azharuddin

ランク: Expert

投稿: 471

参加年月日: 2012/09/17

最近の投稿

HI amith

Thank you emoticon