English 中文(简体)
• 如何在游戏中处理! 框架
原标题:How to handle in Play! framework a form post with jsAction?

I m struggling with it for some time with no results. I want data entered in a form and submitted to be rendered as a new row of a table being on the same page (without the page reload). What I currently have is an item model with several fields, a controller with saveItem action:

public static void saveItem(@Valid SoldItem item) {...

以及当然的形式:

<tr class="itemNew">
    <td>
        <input type="image" id="saveItem" name="&{ Save }" alt="&{ Save }" height="16" src="/public/images/001_06.png" form="itemsTable"/>
        <a href="#/cancelEdits"><image id="cancelEdits" src="/public/images/001_05.png" alt="&{ Cancel }" title="&{ Cancel }" height="16"></a>
    </td>

    <td>
        <div class="item">
            <input class="itemDesc" type="text" size="30" name="item.item.name" placeholder="&{ item.name }" />
        </div>
        <div class="item">
            <textarea class="itemDesc" rows="2" cols="30" name="item.item.description" placeholder="&{ item.description }" ></textarea>
        </div>
    </td>

......

附有一些 Java本:

    this.post( #/saveItem , function (context) {
        var item_def = new Sammy.Object();
        context.log( saveItem - params =   + this.params);
        context.log( saveItem - form_fields = { );
        //for ( var item in this.params.keys()) {
        var items = this.params.keys(true);
        for ( var i = 0; i < items.length; i++) {
            var item = items[i];
            context.log( item:   + item);
            if(item.match(/^item./)) {
                item_def[ : + item] = this.params[item];
            }
        }
        context.log( } );
        context.log( item_def:   + item_def);
        var action = #{jsAction @Invoices.saveItem(item_def) /};
        context.log( action:   + action({item: item_def}));
        this.partial(action({item: item_def}));
    });

后者是Sammy.js,但似乎与案件无关。 我得到的是nothing。 下面是最后两个记录条目的样本:

[Fri Jun 10 2011 01:30:51] item_def: Sammy.Object: {":item.item.name": aaa,":item.item.description": dsfsd,":item.retailPrice": dsfs,":item.rebate": sdf,":item.quantity": dsf,":item.vatRate": d,":item.notes": ds}
[Fri Jun 10 2011 01:30:51 ] action: /invoices/saveitem

<代码>jsAction的文件没有涉及这一问题,我找不到任何例子,因此请帮助我。

最佳回答

So the solution I came up with is:

    this.post( #/saveItem , function (context) {
        var items = this.params.toHash();
        var action = #{jsAction @Invoices.saveItem() /};
        this.send($.post, action(), items)
            .then(function(contents) {
                this.swap(contents);
            });
    });

Some explanation I ve found on the playframework group. When posting from a form there is no need to create full query URL. All the parameters should be sent as the post body. The above example shows use of Sammy.js framework (within Play! framework) and it works pretty well.

问题回答

我认为,这是错误的。

var action = #{jsAction @Invoices.saveItem(item_def) /};

应当:

var action = #{jsAction @Invoices.saveItem(item) /};

页: 1 在您的下行中,项目确实存在,因此没有发送或产出。





相关问题
Manage dependencies in a Play Framework app

I m trying to figure out the proper tools for managing dependencies between JARs. I have a Play Framework app, which imports a JAR (based on another project I m writing). This JAR imports other JARs, ...

Deploy Play! application as executable jar

Is it possible to bundle Play! web application to executable jar instead of war? Could it just be run on localhost at some port just like when using "play run" command? (without the need of installing ...

JPA: Store fileAttachment into the database

I would like to know if there is any way I can store a fileAttachment directly into the database with JPA. I have an attribute: public fileAttachement logo; I have tried to change it to: @Lob ...

Java Web Development and Automatic Feedback

I ve been having a (ironic) play around with the Play Framework and have been impressed thus far. I was just curious as to what other Java frameworks are out there that have a similar feature to Play ...

Java web frameworks

I was looking around to see if there is an equivalent to django/RoR in java. I found: Play Framework Grails Does anyone have ever tried those frameworks, or do you know any other? Are they faster ...

热门标签