You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Shifman <ma...@yale.edu> on 2006/12/05 18:25:26 UTC
[s2] Making LazyDynaBean work with ModelDriven interface
Some folks may be as pig-headed as me or may need to use LazyDynaBeans
as they are translating
from struts1 to struts2. After fooling around, I figured it out but it
is pretty clear to me this is not the way to go.
Below is a simple example.
public final class MyAction extends ActionSupport implements ModelDriven{
private LazyDynaBean f = new LazyDynaBean();
public String execute() throws Exception {
String[] text_field = (String[])f.get("text_field");
//do something with the text_field that came from LazyDynaBean
as a String array
return SUCCESS;
}
public Object getModel(){
return f;
}
}
<s:form action="MyAction">
<s:textfield name="map.text_field" />
<s:submit />
</s:form>
<validators>
<field name="map.text_field">
<field-validator type="required">
<message>Text Field is required.</message>
</field-validator>
</field>
</validators>
There were 2 things that bit me:
1. You have to get the field name from map.text field so that
s:textfield can get it from the "map" on the valuestack and
2. The textfield seems to get a String[] rather than a String and I
don't have any idea how to do it differently.
mas
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [s2] Making LazyDynaBean work with ModelDriven interface
Posted by Mark Menard <ma...@mjm.net>.
On 12/5/06 12:25 PM, "Mark Shifman" <ma...@yale.edu> wrote:
> 2. The textfield seems to get a String[] rather than a String and I
> don't have any idea how to do it differently.
I donĀ¹t know if you can do this because I've never really worked with Struts
1. Can you make the Map in your form a Map<Object,String>? That might make
the values be String instead of String[]. This is only an idea.
I'm not sure OGNL will do this with generics. You could test it easily
enough by making your model just a Map<Object,String> and see if that works.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org