user2269170
user2269170

Reputation: 79

Grails - Send List of objects in params of redirect

My problem is that i want to preview data on index view without saving data in database. For this purpose, I want to send the list of objects in params section of redirect. And on receiving action want to use that list of objects.But when i include as below

def preview(){
//some code
redirect action: "index", params:[planId:params.planId, beamsInfoList: beamsInfoList]
}

I want something like below to happen.

def index() { 
    //some code
    try{

        planInfo.beamInfo = (params.beamsInfoList==null)?planInfo.beamInfo:params.beamsInfoList //beamInfo is also list

        //some code

    Object[] obj = GRMUtils.calculateTotalBeamsPower(planInfo.beamInfo)
    totalPlanPower = (Float)obj[0];
    beamPowerMap= (Map<Integer, String>)obj[1];
    AmMapUtility utility=new AmMapUtility()
    output = utility.generateAMmapFromBeams(planInfo.beamInfo, GRMConstants.POWER_MAP_PAGE);
    if(null==output){
        flash.error = message(code: 'beammap.noinfoerror.message')
    }
    }catch(Exception e){
    log.error "Excepton occured while loading Power Map", e
}
    respond beams, model:[centerLong:output.getCenterLongitude(),centerLat:output.getCenterLatitude(),amMapImageProperty:output.getMapImages(),
        amMapLinesProperty:output.getMapLines(), planId:params.planId, planInfo:planInfo, powersControlCarrier: powersControlCarrier, powersTrafficCarrier:powersTrafficCarrier,satPower: planInfo.satellite.satelliteMaxPower, totalPlanPower: totalPlanPower, gatewayPower: planInfo.gateway.gatewayAggregateEIRP,fesOutputPowerLimit:fesOutputPowerLimit, beamPowerMap: beamPowerMap,powerRangeColorMap:output.getReuseColorMap()]

}

It does not redirect to index method and not showing any errors. Both actions are in same controller. I have used flash, but its not helping either as value reflected on second request. I have tried session too, but i am getting error

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

on some DB fetch. I am stuck. I am new to grails and groovy. Please help.

Edit: i have found my list is large, that is why its not redirecting. Please help me with another alternative like how can i use request attribute if it is possible?

Upvotes: 1

Views: 1163

Answers (1)

user2269170
user2269170

Reputation: 79

I think i have solved the problem. Its working now. All i need to do is to use the request setattribute as

request.beams = beams

And no need to pass the list in params of redirect, which i was earlier used to do. Instead of using redirect, i used forward as below:

request.beams = beams

forward action: "index", params:[planId:params.planId]

Upvotes: 1

Related Questions