grails - How can I access individual values in a gsp file that are generated in a <g:each> tag? -
i have following code in gsp file, used editing individual values of existing list (patientpts)
<g:each var="points" in="${patientpts}"> <b>term: ${points.term} - <g:if test="${points.type.equals('c')}">calculus<br> </g:if> <g:else>perio<br> </g:else></b> <label for="${points.id}01">class 0/1:</label> <input type="text" name="class_01" value="${points.class_01}" id="${points.id}01"> <br> <label for="${points.id}2">class 2: </label> <input type="number" name="class_2" value="${points.class_2}" id="${points.id}2"> <br> <label for="${points.id}3">class 3: </label> <input type="number" name="class_3" value="${points.class_3}" id="${points.id}3"> <br> <label for="${points.id}4">class 4: </label> <input type="number" name="class_4" value="${points.class_4}" id="${points.id}4"> <br> </g:each> <br> <div class="buttons"> <g:link value="save" action="save" params="${[patientpts: patientpts]}">save</g:link> <g:actionsubmit value="cancel" action="index" /> </div>
patientpts list of patientpoints objects following attributes
string coursekey; //stores course key of course patient points object string term; // stores term of patient points object string type; // stores type of patient points object double class_01; //stores points class 0 , class 1 double class_2; //stores points class 2 double class_3; //stores points class 3 double class_4; //stores points class 4
which displays
i have save action in controller in need able @ of these objects , save changes made them, if any. having trouble doing because cant figure out how refer each text field separately, when generated tag. can me out?
it sounds want use array or list binding syntax in gsp. put patientpts objects in set inside of command object such as:
class patientcommand { set<patientpts> patientpts }
in gsp, want bind using index notation:
<g:each var="points" in="${commandinstance.patientpts}" status="i"> ... <input type="text" name="patientpts[${i}]class_01" value="${points.class_01}" id="${points.id}01">
when form submitted , bound patientcommand, data binder create indidual patientpts objects , bind them set (creating , growing automatically).
Comments
Post a Comment