View Full Version : Json

Siva Shankari
28-12-2012, 10:52 AM
I am new to grails, previously i have created a domain like this
My domain:
class Item{
String itemCode
String itemName
String description
String type
MeasurementUnit uom
float unitPrice
to maintain item details. I use this domain to enter both material details as well as product details. In my second domain i have the following fields.
class CostSheet{
String partNo
Item partName
String Description

The partNo details are fetched from the Item domain.

Remote Function:
<g:textField name="costSheetVersion" id="costSheetVersion" value="${fieldValue(bean: costSheetInstance, field: 'costSheetVersion')}" class="textbox1" alt="MAD" onblur="${remoteFunction(controller:'costSheet', action:'checkVersion', params:'\'costSheetVersion=\' + escape(this.value)+\'&partName='+document.getElementById(\'partName\').v alue',

based on the item selected other related values has to be fetched from the first domain by passing through the action then to the javascript.

Action in controller:
def ajaxGetPartIdDetails={
def item=Item.get(params.id)
render item as JSON

Fetch the values from the first domain.

function updatePartIdDetails(e){
var values = eval("(" + e.responseText + ")")

Assigning the fetched value in the corresponding fields.

It worked fine in grails 1.3 but not in grails 2.0. I am able to call the action in an controller and fetch values but unable to call the values in the javascript. I hope i made mistake in JSON

This the action in grails 2
def processCode(){
def processName=ProcessDetails.get(params.id)
I also tried like this too
def processCode(){
def processName=ProcessDetails.get(params.id)
render processName as JSON

But none works out. Kindly provide some suggestion if i am wrong else say me how to proceed further.