Miguel wrote:
Hi,
I'm currently writing a form based on a set, and each object of the
set has it's own textfield and it's own id/name.
The question is the way i read the returned value in the action.
I've tried using a map, but puting the varname[key] doesn't work; How
can I acomplish this using struts2?
The goal is to have the map filled with the keys and values simultaneously.
<s:form id="questedit_form" name="form1" method="post"
action="questionaire/questionaire.action" cssClass=""
targets="#editor">
<s:iterator value="metrics">
<s:set id="description" value="description" />
<s:set id="id" value="id" />
<s:set id="value" value="value" />
Why the s:set tags? They shouldn't be necessary and you're not using the
resulting context variables anyway (you'd have to refer to #id,
#description, etc instead of just id, description, ...).
<s:textfield name="resp[%{id}]" label="%{description}"
value="%{value}" /><br/>
</s:iterator>
<s:submit type="button" name="ButtonF" id="Submit" value="Salvar"
method="save" cssClass="textc" />
</s:form>
I also tried:
<s:textfield name="resp.[%{id}]" label="%{description}" value="%{value}" /><br/>
<s:textfield name="resp.{%{id}}" label="%{description}" value="%{value}" /><br/>
<s:textfield name="resp{%{id}}" label="%{description}" value="%{value}" /><br/>
Have you looked at the generated HTML for any of the four options you
tried? You should be looking for something like name="resp[1]".
IIRC, s:textfield's 'name' attribute is evaluated as OGNL, so the value
you specify must be a valid OGNL expression. So your first attempt would
be roughly equivalent to "%{resp[%{id}]}", which is obviously wrong...
I'd try something like "${'resp['+id+']'}".
That said, why not just copy the data from the set into a map in the
action before showing the form, and avoid the hassle of trying to
convert from one data structure to another in the JSP?
L.
to fill:
package org.unam.mcic.gqm.web;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hibernate.Hibernate;
import org.unam.mcic.metrics.gqm.Metric;
import org.unam.mcic.metrics.gqm.Questionaire;
import org.unam.mcic.metrics.gqm.RespondedQuestionaire;
import org.unam.mcic.metrics.repos.MetricDAO;
import org.unam.mcic.metrics.repos.QuestionaireDAO;
import com.ervacon.bitemporal.TimeUtils;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
public class ResponseAction extends ActionSupport implements Preparable {
....
protected Map<Long,Double> resp = new HashMap<Long,Double>();
public void prepare() throws Exception {
....
}
public String browse(){
....
}
public Map<Long, Double> getResp() {
return resp;
}
public void setResp(Map<Long, Double> resp) {
this.resp = resp;
}
}
Si quieres ser más positivo, pierde un electrón
Miguel Ruiz Velasco S.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]