从javascript Play框架绑定表单

时间:2013-05-16 15:26:35

标签: javascript playframework playframework-2.0

有没有办法使用这段代码:

Form<StatusSolicitacao> status = form(StatusSolicitacao.class).bindFromRequest();

但数据来自javascript?

---更多信息---

首先我展示清单:

<div id="backtabela">
    <div id="tabela">
        <table>
        <tr><td><a href="javascript:;" onclick="enviar('formCadStatus')" id="botao">Cadastrar Status</a></td></tr>  
            <tr>
                <td id="cabecalho">Descrição</td>
                <td id="cabecalho">Acoes</td>
            </tr>
            @for(status <- lista){
            <tr>
                <td>@status.getDescricao()</td>
                <td><a href="javascript:;" onclick="enviar('formAltStatus/@status.getCodStatus()')"><img src="@routes.Assets.at("img/edit.png")" alt="" title="Editar"/></a>
                    <a href="javascript:;" onclick="enviar('removerStatus/@status.getCodStatus()')"><img src="@routes.Assets.at("img/erase.png")" alt="" title="Remover"/></a>
                </td>
            </tr>
            }
        </table>
    </div>
</div>

然后我点击Cadastrar状态以注册新数据。

表格:

@(status: Form[StatusSolicitacao])

@import helper._
@implicitFieldConstructor = @{ FieldConstructor(formPattern.f) }


        <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
        <fieldset id="fieldset">
        <legend>Novo Status</legend>
        <div id="form">         
            <br/><br/><br/><br/><br/>
        @form(routes.StatusController.cadastrarStatus()) {
                    <br/><br/><br/><br/><br/>
                    @inputText(status("descricao"), '_label -> "Descrição", '_help->"")            
                <div class="actions">
                    <input type="submit" value="Cadastrar" class="btn primary" id="botao">                  
                </div>
          </div>
          </fieldset>
           <a href="javascript:;" onclick="enviar('listarStatus')" class="btn">Cancelar</a> 
            }

注意:所有这些内容都在这个html中的div nova中:

<!DOCTYPE html>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Solicitação Compra</title>
        <link rel="stylesheet" media="screen" href="@routes.Assets.at("css/geral.css")">
        <link rel="shortcut icon" type="img/png" href="@routes.Assets.at("img/favicon.png")">
        <script src="@routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"></script>
        <script src="@routes.Assets.at("javascripts/init.js")" type="text/javascript"></script>
    </head>
    <body>
    <div id="geral-flow">
    <div id="topo">
        <div id="logo" style="display:none;">
        <a href="index.html"><img src="@routes.Assets.at("img/logotipo-pequeno.png")" alt="titulo" id="tituloPequeno"/></a>
        </div>
        <div id="acessos">
            <div id="pesquisa">
                <input type="text" name="search" id="search" value="Pesquisa"
                    onfocus="this.value=''" onblur="this.value='Pesquisa'"></input>
                <ul></ul>
            </div>
            <div id="acessoRapido" >
                <a href="@routes.DepartamentoController.deslogar()" title="Sair" id="sair"></a>
                <a href="@routes.Application.index()" title="Home" id="home"></a> 
                <a href="#" title="Pesquisa" id="pesquisar"></a>
            </div>
        </div>
    </div>
    <div id="conteudo">
    <div id="titulo">
                <ul>
                <li style="background-position:-2px -107px;"><h2>Solicitações</h2></li>
                </ul>
            </div>              
    <div id="separador"></div>  
    <div id="menu">
            <ul>
                <li class="solicitacao"><a href="javascript:;" onclick="enviar('listarSolicitacaoCompra')">Solicitaçoes</a><br /></li>  
                <li class="departamento"><a href="javascript:;" onclick="enviar('listarDepartamento')">Departamentos</a><br /></li>             
                <li class="responsavel"><a href="javascript:;" onclick="enviar('listarResponsavel')">Responsavel</a><br /></li>
                <li class="status"><a href="javascript:;" onclick="enviar('listarStatus')">Status</a><br /></li>            
            </ul>
    </div>  
    <div id="nova"></div>

     <div class="clear"></div>     
    </div>
    </div>        
    </body>
</html>

但是当我在后面的替补席上保存我的新唱片时,html没有出现。

1 个答案:

答案 0 :(得分:0)

如果你的名字属性与StatusSolicitacao属性重合,我认为它可以正常工作

否则只需使用以下String attribute = Form.form().bindFromRequest().get("attribute");

即可