[prev in list] [next in list] [prev in thread] [next in thread] 

List:       struts-user
Subject:    Re: input Map
From:       Miguel <miguelrvs () gmail ! com>
Date:       2008-08-28 22:16:10
Message-ID: d8b42bcf0808281516wfa3ab58sc17210518a5ef415 () mail ! gmail ! com
[Download RAW message or body]

Just for the record, the problem wasn't from the action to the jsp,
but from the submited action to load the data.
Continued trying and this was the thing that worked:

ResponseAction-conversion.properties:

Key_resp=java.lang.Long
Element_resp=java.lang.Double
CreateIfNull_resp=true

ResponseAction.java:
...
public class ResponseAction extends ActionSupport implements Preparable {
	protected Map<Long,Double> resp = new HashMap<Long,Double>();

	public void prepare() throws Exception {
...
	}
	
	public String save(){
...
}
	public Map<Long, Double> getResp() {
		return resp;
	}

	public void setResp(Map<Long, Double> resp) {
		this.resp = resp;
	}
}


detail.jsp:
...
<s:iterator value="metrics">
	<s:set id="description" value="description" />
	<s:set id="id" value="id" />
	<s:textfield name="resp[%{id}]" label="%{description}" value="" /><br/>
</s:iterator>

The trick was the Action-conversion.properties, so the framework can
convert to a proper value and populate it. Please note that you need
to specify the fully qualified class name, even on java.lang clases.

Si quieres ser más positivo, pierde un electrón
Miguel Ruiz Velasco S.



On Thu, Aug 28, 2008 at 14:06, Laurie Harper <laurie@holoweb.net> wrote:
> 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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic