Fórumok

Calling method

Alfresco_Liferay developer, módosítva 9 év-val korábban

Calling method

New Member Bejegyzések: 18 Csatlakozás dátuma: 2014.09.22. Legújabb bejegyzések
Hi

I have simple question about calling java method in jsp file..

I crate following method in java

public boolean add(ActionRequest actionRequest,ActionResponse response)
{
boolean flag=true;
if(----------)
{
flag=true;
}
else
{
flag=false;
}

return flag;
}


In view.jsp file How can I call this method?
If flag=false then I want to put error message.
<aui:form action="<%=???????? %>" enctype="multipart/form-data" method="post" >
How is it possible??
Thanks in advance
thumbnail
Manali Lalaji, módosítva 9 év-val korábban

RE: Calling method

Expert Bejegyzések: 362 Csatlakozás dátuma: 2010.03.09. Legújabb bejegyzések
Hi,

I dont think you should call java method from jsp like this. Instead you can create actionUrl and map this action name and then set your flag in response which shall be fetched in render method.
Once you set that attribute in render method, you can access that in jsp.

HTH!
thumbnail
Andew Jardine, módosítva 9 év-val korábban

RE: Calling method

Liferay Legend Bejegyzések: 2416 Csatlakozás dátuma: 2010.12.22. Legújabb bejegyzések
In your JSP add --

<portlet:actionurl name="myAction" var="myActionURL" />

for your form ...


<aui:form ... action="${myActionURL}"> 
...

</aui:form>

... and then update your Java code to use


@ProcessAction(name="myAction")
public boolean add(ActionRequest actionRequest,ActionResponse response)
{
   if ( flag == Boolean.FALSE )
        SessionErrors.add(actionRequest, "you-language-key-here")

}

and then to show the error in the JSP
[code]
<liferay-ui:error key="you-language-key-here" />

thumbnail
Pankaj Kathiriya, módosítva 9 év-val korábban

RE: Calling method

Liferay Master Bejegyzések: 722 Csatlakozás dátuma: 2010.08.05. Legújabb bejegyzések
You can have action as <portlet:actionURL name="add"/> .
<aui:form action='<portlet:actionURL name="add"/>' enctype="multipart/form-data" method="post" >
that will call add method(as an action phase).

To achieve error message thing, you can add error message in SessionErrors based on condition and have error message displayed on front end.
As such AFAIK you can not get boolean return value from this method.
Alfresco_Liferay developer, módosítva 9 év-val korábban

RE: Calling method

New Member Bejegyzések: 18 Csatlakozás dátuma: 2014.09.22. Legújabb bejegyzések
Thank you all for the help