How to add multiple array values in Grails -


it gives me error while submitting multiple values in database error: indexoutofbond

<form action="emp/forsubmit" method=" post">    <input id="emp[0].name" name="emp[0].name"  type="text"/>    <input id="emp[0].lastname" name="emp[0].lastname"  type="text"/> <input id="emp[1].name" name="emp[1].name"  type="text"/> <input id="emp[1].lastname" name="emp[1].lastname"  type="text"/> </form> 

i using mongodb db

controller source code :

def update(){  if(empinstance.getemp_history() == null || empinstance.getemp_history().size() == 0) {             empinstance.setemp_history(new arraylist<emphistory>());             empinstance.getemp_history().add(new employmenthistory());         }  empinstance.properties = params } 

use same name attribute value:

first: <input type="text" name="firstname"/> first: <input type="text" name="lastname"/>  second: <input type="text" name="firstname"/> second: <input type="text" name="lastname"/> 

and processed array grails when form has been submitted, , populate domain object every loop round :

params.firstname.eachwithindex { value, index ->      // use index access values in other array      // params.lastname[index]      def mydomain = new mydomain()      mydomain.firstname = value      mydomain.lastname  = params.lastname[index]      mydomain.save() } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -