开发者

i put a value into an input type text but with null value in params.descrption.Why?

开发者 https://www.devze.com 2023-01-29 00:43 出处:网络
this开发者_JAVA百科 is the gsp code: td align=\"left\" class=\"pinkbox\" style=\"height: 35px\" width=\"43%\">

this开发者_JAVA百科 is the gsp code:

td align="left" class="pinkbox" style="height: 35px" width="43%">
${fieldValue(bean: bookInstance, field: "description")}<br />
input type="text" id="description" name="description" value="${fieldValue(bean: bookInstance, field: "description")}" size="30px"  />
g:link controller="conference" action="edit" id="${bookInstance.id}">Update </g:link></td>

groovy code in the controller:

def edit ={
  println params.description
  def bookInstance = Book.get(params.id)
  try{
    bookInstance.description = params.description
    bookInstance.save()

    redirect(action:'show',id:bookInstance.id)
  }catch(Exception e){
    flow.message ="an error occurred during update"
    redirect(action:'show',id:bookInstance.id)
  }
}

it returns a null value while i insert a value inside the textbox control. i try omit value attribute from input type text but without any effect


I think your problem is that you are using a link to call the controller action, and you are not submitting any params data. Try adding a params attribute to your g:link as detailed in the g:link documentation:

http://www.grails.org/Tag+-+link

Note that you are going to have to populate the params from the values in the input with javascript, if you really want to use a link like this.

Alternatively, and perhaps more correct, is using a form. You should try something like

<g:form controller='thecontroller' method='edit'>    
  <g:textarea name="" value="" type="text"></g:textarea>
   ... more fields here including  a submit ...
</g:form>

If you really want to have the 'button' be a link, you can use javascript to have it submit the form. However, using the form as intended is probably best. Grails is all about conventions...


input type="hidden" name="Id"value="${bookInstance.id}">

td align="left" class="pinkbox" style="height: 35px" width="43%">

${fieldValue(bean: bookInstance, field: "description")}

g:textField type="text" name="description" value="${fieldValue(bean: bookInstance, field: "description")}" size="30px" />

g:actionSubmit action='edit' value="Update" >

0

精彩评论

暂无评论...
验证码 换一张
取 消