7

私のjspには次のコードがあります:

<portlet:actionURL name="addDetails" var="addDetailsURL" />
<aui:form name="addDetails" action="<%=addDetailsURL.toString() %>" method="post" >
        <aui:input type="text" label="name:" name="name" value="" />
        <aui:input type="text" label="surname:" name="surname" value="" />
        <aui:input type="text" label="age:" name="age" value="" />
        <aui:button type="submit" value="addDetails" />
</aui:form>

ライフレイを使用しています。Java クラスで処理されるこのデータを送信したいと考えています。私のJavaクラスにはほとんど関数がありません。上記のjspで、フォームを送信した後にJavaの特定の関数にアクセスする必要があることをどのように指定すればよいですか?

4

6 に答える 6

14

ポートレットが を継承する場合MVCPortletは、actionURL と同じ「名前」で、ActionRequestandActionResponse引数を取る public メソッドを作成するだけです。

public void addDetails(ActionRequest req, ActionResponse rsp) {
    // ...
}
于 2013-03-11T06:51:57.937 に答える
9

記録のために、注釈を使用することもできます。たとえば、次の jsp があります。

<portlet:actionURL var="urlAction">
    <portlet:param name="javax.portlet.action" value="myAction"/>
</portlet:actionURL>

<aui:form action="${urlAction}" method="post">
    <aui:input type="text" label="name:" name="name" value="" />
    <aui:button type="submit" value="Submit" />
</aui:form>

そして、あなたのこのJavaメソッドMVCPortlet

@ProcessAction(name = "myAction")
public void method(ActionRequest actionRequest, ActionResponse actionResponse) {
    // ...
}
于 2013-03-12T11:37:25.210 に答える
6

1 つのアクションのみを処理する場合:

ポートレット

@Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException
{
    // TODO Auto-generated method stub
    super.processAction(actionRequest, actionResponse);
}

JSP

<form action="<portlet:actionURL />" method="post">
    <aui:button type="submit" value="addDetails" />
</form>

複数のアクション メソッドが必要な場合:

public void myAction(ActionRequest request, ActionResponse response)
{
     Long id = ParamUtil.getLong(request, "myParam");
     // TODO
}

JSP

<portlet:actionURL name="myAction" var="myActionVar">
    <portlet:param name="myParam" value="${currentElement.id}"></portlet:param>
</portlet:actionURL>

<a href="${myActionVar}">Click Me!</a>

しかし、あなたはおそらくそうするでしょう:

ポートレット

@Override
public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException
{
    String action = request.getParameter("action");

    if(action.equalsIgnoreCase("myAction")){
        // handle AJAX call
    }
}

JSP

<portlet:resourceURL var="resourceUrl" />
<input id="resourceURL" type="hidden" value="${resourceUrl}" />

JavaScript

$.post($('#resourceURL').val(),{
    action : 'myAction'
}).done(function(result){
    alert('Action completed successfully!')
});
于 2013-03-11T06:50:22.997 に答える
3

MVCPortlet ではなく GenericPortlet のようなものを使用している場合は、次のように actionURL に param を追加します。

<portlet:actionURL name="addDetails" var="addDetailsURL" >
<portlet:param name="method" value="addDetails"/>
</portlet:actionURL>

次に、processAction メソッドで、メソッド タイプのチェックを次のように処理します。

public void processAction(ActionRequest aReq, ActionResponse aResp) throws IOException,
            PortletException {

        final String method = aReq.getParameter("method");

        if ( method != null && method.equals("addDetails")) 
        {   
            addDetails(aReq, aResp);

        } 
于 2013-06-12T17:50:58.207 に答える
2

これをコントローラークラスに貼り付けます

public void addDetails(ActionRequest actionRequest, ActionResponse actionResponse) {
    //this method will be called on submitting the form
    System.out.println("addDetails");
}

または、次のように使用できます

@ProcessAction(name="addDetails")
public void myaddDetails(ActionRequest actionRequest, ActionResponse actionResponse) {
    //this method will be called on submitting the form
    System.out.println("addDetails");
}
于 2015-11-01T23:13:34.817 に答える
1

Java クラスが MVCPortlet を拡張している場合、メソッド名だけが actionURL 名、つまり addDetails と一致する必要があります。クラスが GenericPortlet を拡張している場合、@ProcessAction(name="addDetails") のようなメソッドの上に同じアノテーションを指定する必要があります。この場合、メソッドの名前は異なる場合があります。

于 2014-07-13T13:48:18.147 に答える