I have already searched and found several approaches here, but I cannot get them to work for my project.
I want to show an edit page for a list of objects that need to be updated immediately. I am using a model-based approach to achieve this, but I cannot get it to work properly. I can always display and iterate over the list and its values, but I cannot change its values.
So here is what I am doing now:
I have a Teilzeitgrad model in my database that has some simple attributes with getters and setters.
public class Teilzeitgrad { private Date datumAb; private Date datumBis; private double betrag;
In my Action class, I implement the ModelDriven interface with a list of Teilzeitgrad objects
public class DienstabschnittViewJahrAction implements ModelDriven<List<Teilzeitgrad>>, Preparable { List<Teilzeitgrad> teilzeitgrads; private String tzgTypKey; private Integer jahrIndex; public String execute() { return SUCCESS; } public List<Teilzeitgrad> getModel() { if(teilzeitgrads == null) { teilzeitgrads = getTeilzeitgradListByTypAndJahr(getTzgTypKey(), getJahrIndex()); } return teilzeitgrads; } public List<Teilzeitgrad> getTeilzeitgrads() { return teilzeitgrads; } public void setTeilzeitgrads(List<Teilzeitgrad> teilzeitgrads) { this.teilzeitgrads = teilzeitgrads; } @Override public void prepare() throws Exception {
The action mapping in struts.xml is defined as follows:
<action name="*/auth/GroupAdmin/processEditDienstabschnittJahr" method="execute" class="org.hocon.ul.portal.action.DienstabschnittViewJahrAction"> <result name="success" type="redirect">${referer}</result> </action>
In my JSP file, I repeat the model object, displaying its values ββin text fields or lists as follows:
<ul:form action="auth/GroupAdmin/processEditDienstabschnittJahr"> <s:iterator value="model" status="rowStatus"> <tr> <td style="text-align: center;"> <s:date name="model.get(#rowStatus.index).datumAb" var="datumAb_DE" format="dd.MM.yyyy" /> <s:textfield style="width:70px;" name="model.get(#rowStatus.index).datumAb" value="%{#datumAb_DE}" label="DatumAb"></s:textfield > </td> <td style="text-align:center;"> <s:date name="model.get(#rowStatus.index).datumBis" var="datumBis_DE" format="dd.MM.yyyy" /> <s:textfield style="width:70px;" name="model.get(#rowStatus.index).datumBis" value="%{#datumBis_DE}" label="DatumBis"></s:textfield > </td> <td class="currency"> <s:set var="tzgBetrag"> <fmt:formatNumber type="NUMBER" maxFractionDigits="0"><s:property value="%{getBetrag()*100}"></s:property></fmt:formatNumber> </s:set> <s:textfield style="width:30px;" maxlength="3" name="model.get(#rowStatus.index).betrag" value="%{#tzgBetrag}" label="Betrag"></s:textfield > </td> </tr> </s:iterator> <s:submit style="width:24px; height:24px;" type="image" src="../../../res/24px/floppy-disk.png" value="Speichern"></s:submit> </ul:form>
ul-tag is a custom taglib that adds a client url parameter to the action path.
So when I show the page, it shows all my Teilzeitgrad entries with a row for each entry. But when I submit the form, the list of my models is not populated. Setter setTeilzeitgrads(List<Teilzeitgrad> teilzeitgrads) is not even called at all. I also tried accessing the list in array syntax:
<s:textfield style="width:70px;" name="teilzeitgrads[#rowStatus.index].datumAb" value="%{#datumAb_DE}" label="DatumAb"></s:textfield >
but it also did not work.
Any help resolving this case is appreciated! Thanks in advance!
Lenzo