How to Create a Dynamic Radio Button in the Grails Controller

advertisements

Currently I am working with grails and MySQL.

I have to create a dynamic radio button in the controller and pass to the view. How can I do this?

For example: radio button with yes or no and male or female

These values are now in the database. Now my problem is how can I create the radio button in the controller and pass it to the grails view?

List queryData
String s="";
for(int i=0;i<eventformAttri.size();i++){
    queryData=formField.masterTableQuery(eventformAttri[i].fieldQuery.toString()) //to fetch the radio buttons values
    for(int ii=0;ii<queryData.size();ii++){
        System.out.println("list data "+queryData[ii].field1)
        s+=queryData[ii].field1+" <input type='radio' name='myGroup"+i+"' value="+queryData[ii].field2+" />";
    }
    s+=",";
}
def vformData=s.split(',');
render(view:'/auditor/formView',model:[eventformAttri:eventformAttri,queryData:vformData])


You should create your radio button in your view, and use the embedded jquery library to do that. For instance, combine your jquery script in the view with a remotelink to interact with your controller:

$('input:radio[title=YOUR TITLE]').attr('checked',true);

    <g:remoteLink controller="yourcontroller" action="youraction" update="[success: 'results']" onSuccess="yourFunction(data) ">Your link</g:remoteLink>