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/04 18:56:51 UTC
[s2] LazyDynaBean and ModelDriven interface
Does anybody have an example of using a LazyDynaBean with the
ModelDriven interface?
http://struts.apache.org/2.x/docs/struts-1-solutions.html implies that
it should work.
I have a simple action:
public final class MyAction extends ActionSupport implements ModelDriven{
private LazyDynaBean f;
public String execute() throws Exception {
String my_field = (String)f.get("my_field");
LOG.fatal(my_myfield); //nothing here :-(
return SUCCESS;
}
public Object getModel() {
return f = new LazyDynaBean();
}
}
I don't get anything from the LazyDynaBean.
If I use a simple pojo like
public class myBean {
String my_field;
public String getMy_field() {
return my_field;
}
public void setMy_field(String my_field) {
this.my_field= my_field
}
Things work.
What am I missing or doing wrong?
Thanks in advance
mas
--
Mark Shifman MD. Ph.D.
Yale Center for Medical Informatics
Phone (203)737-5219
mark.shifman@yale.edu
---------------------------------------------------------------------
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
[s2] Making LazyDynaBean work with ModelDriven interface
Posted by Mark Shifman <ma...@yale.edu>.
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] LazyDynaBean and ModelDriven interface
Posted by Mark Shifman <ma...@yale.edu>.
Mark Shifman wrote:
> Does anybody have an example of using a LazyDynaBean with the
> ModelDriven interface?
> http://struts.apache.org/2.x/docs/struts-1-solutions.html implies that
> it should work.
>
> I have a simple action:
> public final class MyAction extends ActionSupport implements ModelDriven{
> private LazyDynaBean f;
> public String execute() throws Exception {
> String my_field = (String)f.get("my_field");
> LOG.fatal(my_myfield); //nothing here :-(
Opps I made a typo for this example should be:
LOG.fatal(my_field);
> return SUCCESS;
> }
> public Object getModel() {
> return f = new LazyDynaBean();
> }
> }
>
> I don't get anything from the LazyDynaBean.
> If I use a simple pojo like
> public class myBean {
> String my_field;
> public String getMy_field() {
> return my_field;
> }
>
> public void setMy_field(String my_field) {
> this.my_field= my_field
> }
>
> Things work.
>
> What am I missing or doing wrong?
> Thanks in advance
> mas
>
--
Mark Shifman MD. Ph.D.
Yale Center for Medical Informatics
Phone (203)737-5219
mark.shifman@yale.edu
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org