Fórum

Calling method

Alfresco_Liferay developer, modificado 9 Anos atrás.

Calling method

New Member Postagens: 18 Data de Entrada: 22/09/14 Postagens Recentes
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, modificado 9 Anos atrás.

RE: Calling method

Expert Postagens: 362 Data de Entrada: 09/03/10 Postagens Recentes
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, modificado 9 Anos atrás.

RE: Calling method

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
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, modificado 9 Anos atrás.

RE: Calling method

Liferay Master Postagens: 722 Data de Entrada: 05/08/10 Postagens Recentes
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, modificado 9 Anos atrás.

RE: Calling method

New Member Postagens: 18 Data de Entrada: 22/09/14 Postagens Recentes
Thank you all for the help