You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Philippe Goncalves <ph...@gmail.com> on 2010/12/16 04:00:58 UTC

Beans stay null

Hi all!

Coming from the Struts1 world, I find Struts2 really convenient!
But I have a simple problem, maybe I miss something. I've read some
tutorials about Struts2 but didn't find something... Here it is:

I'm modifying an actual project based on struts2, spring and freemarker. I
have to add some functionnalities to a page, so I have to modify an Action,
by adding three simple pojo objects, with the getters/setters (these
class/variables names are fictional):
*
public class MyAction extends ActionSupport{

private Bean bean;
private Bean2 bean2;
private Bean3 bean3;

public Bean getBean(){
   return bean;
}

public void setBean(Bean bean){
  this.bean = bean;
}
...
}

public class Bean{
  private String title;
  private String description;

  public String getTitle(){
    return title;
  }

  public void setTitle(String title){
    this.title = title;
  }

  public String getDescription(){
    return description;
  }

  public void setDescription(String description){
    this.description = description;
  }

}*
*...*

All these objects have a title and description as variables, so on my page,
I have these inputs:
*
<@s.textfield name="bean.title" />
<**@s.textfield** name="bean.description" />
...*

When I first print the page (input method of my action), my beans are well
filled with the values I put on the action. But when I submit the page, all
my beans stay at null (debugger on the action class)! And I don't know why
It's been one day and an half that I'm trying to get this working, but I
don't why my objects stay at null after the submit of my page (I've already
checked the name of my variables, trying to rename my beans, etc.)

Could someone please tell me if I am missing something? I thought that with
struts2, you just have to declare you're objects (String, Integer, Self made
beans, etc.) on the Action with the good getters/setters and Struts take
care of this automatically (not like Struts1 where you have to declare your
beanform on the struts.xml).


Thanks!

-- 
Philippe Goncalves
http://www.linkedin.com/in/philippegoncalves
http://www.philippegoncalves.com
Tel: +15146326816

Re: Beans stay null

Posted by Philippe Goncalves <ph...@gmail.com>.
Thanks for your help maurizio, I found something about my problem: I'm
developping a plugin on the Jive SBS Software. To do this, all the action
class must extend a JiveActionSupport class. I changed by ActionSupport
directly, and my beans are not null anymore. But I can't do this way because
the plugins on Jive must extend JiveActionSupport. I'm gonna send a mail to
their support.

Thanks

On Wed, Dec 15, 2010 at 11:12 PM, Maurizio Cucchiara <
maurizio.cucchiara@gmail.com> wrote:

> It's very strange odd. Could you attach at least your action java file,
> struts.xml and freemarker template?
>
> Maurizio Cucchiara
>
> Il giorno 16/dic/2010 05.06, "Philippe Goncalves" <
> philippe.goncalves@gmail.com> ha scritto:
> > Unfortunately nothing :(
> >
> > On Wed, Dec 15, 2010 at 10:25 PM, Maurizio Cucchiara <
> > maurizio.cucchiara@gmail.com> wrote:
> >
> >> Did you see if you get any exception? (like conversion errors)
> >>
> >> Maurizio Cucchiara
> >>
> >> Il giorno 16/dic/2010 04.21, "Philippe Goncalves" <
> >> philippe.goncalves@gmail.com> ha scritto:
> >> > It's before the redirection.
> >> > I come to my page: Ok, my variables are all here
> >> > I submit my page: when It comes to my Action class (method execute) to
> >> save
> >> > the information submited, my bean objects are all null on the class,
> but
> >> > they are present on my request object. The only variables not null are
> >> the
> >> > simple Objects on my class (String, Integer, etc.). It's like it
> doesn't
> >> > want to deal with my pojo objects...
> >> >
> >> > On Wed, Dec 15, 2010 at 10:13 PM, Maurizio Cucchiara <
> >> > maurizio.cucchiara@gmail.com> wrote:
> >> >
> >> >> As I guess, when struts do a redirect lost your bean parameters.
> >> >> Try to remove and see what happens
> >> >>
> >> >> Maurizio Cucchiara
> >> >>
> >> >> Il giorno 16/dic/2010 04.09, "Philippe Goncalves" <
> >> >> philippe.goncalves@gmail.com> ha scritto:
> >> >> Sure, here it is:
> >> >>
> >> >> <action name="edit-event"
> >> >> class="com.jivesoftware.community.ext.event.action.MyAction">
> >> >> <result name="success"
> >> >> type="redirect">/events/${event.ID}</result>
> >> >> <result name="input"
> >> >>
> >> >>
> >>
> >>
>
> type="freemarker">/plugins/event-type-plugin/resources/templates/edit-event.ftl</result>
> >> >> <result name="cancel"
> >> >> type="redirect">/events/${event.ID}</result>
> >> >> </action>
> >> >>
> >> >>
> >> >> On Wed, Dec 15, 2010 at 10:05 PM, Maurizio Cucchiara <
> >> >> maurizio.cucchiara@gmail.com> wrote:
> >> >>
> >> >> > Coul...
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Philippe Goncalves
> >> > http://www.linkedin.com/in/philippegoncalves
> >> > http://www.philippegoncalves.com
> >> > Tel: +15146326816
> >>
> >
> >
> >
> > --
> > Philippe Goncalves
> > http://www.linkedin.com/in/philippegoncalves
> > http://www.philippegoncalves.com
> > Tel: +15146326816
>



-- 
Philippe Goncalves
http://www.linkedin.com/in/philippegoncalves
http://www.philippegoncalves.com
Tel: +15146326816

Re: Beans stay null

Posted by Maurizio Cucchiara <ma...@gmail.com>.
It's very strange odd. Could you attach at least your action java file,
struts.xml and freemarker template?

Maurizio Cucchiara

Il giorno 16/dic/2010 05.06, "Philippe Goncalves" <
philippe.goncalves@gmail.com> ha scritto:
> Unfortunately nothing :(
>
> On Wed, Dec 15, 2010 at 10:25 PM, Maurizio Cucchiara <
> maurizio.cucchiara@gmail.com> wrote:
>
>> Did you see if you get any exception? (like conversion errors)
>>
>> Maurizio Cucchiara
>>
>> Il giorno 16/dic/2010 04.21, "Philippe Goncalves" <
>> philippe.goncalves@gmail.com> ha scritto:
>> > It's before the redirection.
>> > I come to my page: Ok, my variables are all here
>> > I submit my page: when It comes to my Action class (method execute) to
>> save
>> > the information submited, my bean objects are all null on the class,
but
>> > they are present on my request object. The only variables not null are
>> the
>> > simple Objects on my class (String, Integer, etc.). It's like it
doesn't
>> > want to deal with my pojo objects...
>> >
>> > On Wed, Dec 15, 2010 at 10:13 PM, Maurizio Cucchiara <
>> > maurizio.cucchiara@gmail.com> wrote:
>> >
>> >> As I guess, when struts do a redirect lost your bean parameters.
>> >> Try to remove and see what happens
>> >>
>> >> Maurizio Cucchiara
>> >>
>> >> Il giorno 16/dic/2010 04.09, "Philippe Goncalves" <
>> >> philippe.goncalves@gmail.com> ha scritto:
>> >> Sure, here it is:
>> >>
>> >> <action name="edit-event"
>> >> class="com.jivesoftware.community.ext.event.action.MyAction">
>> >> <result name="success"
>> >> type="redirect">/events/${event.ID}</result>
>> >> <result name="input"
>> >>
>> >>
>>
>>
type="freemarker">/plugins/event-type-plugin/resources/templates/edit-event.ftl</result>
>> >> <result name="cancel"
>> >> type="redirect">/events/${event.ID}</result>
>> >> </action>
>> >>
>> >>
>> >> On Wed, Dec 15, 2010 at 10:05 PM, Maurizio Cucchiara <
>> >> maurizio.cucchiara@gmail.com> wrote:
>> >>
>> >> > Coul...
>> >>
>> >
>> >
>> >
>> > --
>> > Philippe Goncalves
>> > http://www.linkedin.com/in/philippegoncalves
>> > http://www.philippegoncalves.com
>> > Tel: +15146326816
>>
>
>
>
> --
> Philippe Goncalves
> http://www.linkedin.com/in/philippegoncalves
> http://www.philippegoncalves.com
> Tel: +15146326816

Re: Beans stay null

Posted by Philippe Goncalves <ph...@gmail.com>.
Unfortunately nothing :(

On Wed, Dec 15, 2010 at 10:25 PM, Maurizio Cucchiara <
maurizio.cucchiara@gmail.com> wrote:

> Did you see if you get any exception? (like conversion errors)
>
> Maurizio Cucchiara
>
> Il giorno 16/dic/2010 04.21, "Philippe Goncalves" <
> philippe.goncalves@gmail.com> ha scritto:
> > It's before the redirection.
> > I come to my page: Ok, my variables are all here
> > I submit my page: when It comes to my Action class (method execute) to
> save
> > the information submited, my bean objects are all null on the class, but
> > they are present on my request object. The only variables not null are
> the
> > simple Objects on my class (String, Integer, etc.). It's like it doesn't
> > want to deal with my pojo objects...
> >
> > On Wed, Dec 15, 2010 at 10:13 PM, Maurizio Cucchiara <
> > maurizio.cucchiara@gmail.com> wrote:
> >
> >> As I guess, when struts do a redirect lost your bean parameters.
> >> Try to remove and see what happens
> >>
> >> Maurizio Cucchiara
> >>
> >> Il giorno 16/dic/2010 04.09, "Philippe Goncalves" <
> >> philippe.goncalves@gmail.com> ha scritto:
> >> Sure, here it is:
> >>
> >> <action name="edit-event"
> >> class="com.jivesoftware.community.ext.event.action.MyAction">
> >> <result name="success"
> >> type="redirect">/events/${event.ID}</result>
> >> <result name="input"
> >>
> >>
>
> type="freemarker">/plugins/event-type-plugin/resources/templates/edit-event.ftl</result>
> >> <result name="cancel"
> >> type="redirect">/events/${event.ID}</result>
> >> </action>
> >>
> >>
> >> On Wed, Dec 15, 2010 at 10:05 PM, Maurizio Cucchiara <
> >> maurizio.cucchiara@gmail.com> wrote:
> >>
> >> > Coul...
> >>
> >
> >
> >
> > --
> > Philippe Goncalves
> > http://www.linkedin.com/in/philippegoncalves
> > http://www.philippegoncalves.com
> > Tel: +15146326816
>



-- 
Philippe Goncalves
http://www.linkedin.com/in/philippegoncalves
http://www.philippegoncalves.com
Tel: +15146326816

Re: Beans stay null

Posted by Maurizio Cucchiara <ma...@gmail.com>.
Did you see if you get any exception? (like conversion errors)

Maurizio Cucchiara

Il giorno 16/dic/2010 04.21, "Philippe Goncalves" <
philippe.goncalves@gmail.com> ha scritto:
> It's before the redirection.
> I come to my page: Ok, my variables are all here
> I submit my page: when It comes to my Action class (method execute) to
save
> the information submited, my bean objects are all null on the class, but
> they are present on my request object. The only variables not null are the
> simple Objects on my class (String, Integer, etc.). It's like it doesn't
> want to deal with my pojo objects...
>
> On Wed, Dec 15, 2010 at 10:13 PM, Maurizio Cucchiara <
> maurizio.cucchiara@gmail.com> wrote:
>
>> As I guess, when struts do a redirect lost your bean parameters.
>> Try to remove and see what happens
>>
>> Maurizio Cucchiara
>>
>> Il giorno 16/dic/2010 04.09, "Philippe Goncalves" <
>> philippe.goncalves@gmail.com> ha scritto:
>> Sure, here it is:
>>
>> <action name="edit-event"
>> class="com.jivesoftware.community.ext.event.action.MyAction">
>> <result name="success"
>> type="redirect">/events/${event.ID}</result>
>> <result name="input"
>>
>>
type="freemarker">/plugins/event-type-plugin/resources/templates/edit-event.ftl</result>
>> <result name="cancel"
>> type="redirect">/events/${event.ID}</result>
>> </action>
>>
>>
>> On Wed, Dec 15, 2010 at 10:05 PM, Maurizio Cucchiara <
>> maurizio.cucchiara@gmail.com> wrote:
>>
>> > Coul...
>>
>
>
>
> --
> Philippe Goncalves
> http://www.linkedin.com/in/philippegoncalves
> http://www.philippegoncalves.com
> Tel: +15146326816

Re: Beans stay null

Posted by Philippe Goncalves <ph...@gmail.com>.
It's before the redirection.
I come to my page: Ok, my variables are all here
I submit my page: when It comes to my Action class (method execute) to save
the information submited, my bean objects are all null on the class, but
they are present on my request object. The only variables not null are the
simple Objects on my class (String, Integer, etc.). It's like it doesn't
want to deal with my pojo objects...

On Wed, Dec 15, 2010 at 10:13 PM, Maurizio Cucchiara <
maurizio.cucchiara@gmail.com> wrote:

> As I guess, when struts do a redirect lost your bean parameters.
> Try to remove and see what happens
>
> Maurizio Cucchiara
>
> Il giorno 16/dic/2010 04.09, "Philippe Goncalves" <
> philippe.goncalves@gmail.com> ha scritto:
> Sure, here it is:
>
> <action name="edit-event"
> class="com.jivesoftware.community.ext.event.action.MyAction">
>           <result name="success"
> type="redirect">/events/${event.ID}</result>
>           <result name="input"
>
> type="freemarker">/plugins/event-type-plugin/resources/templates/edit-event.ftl</result>
>           <result name="cancel"
> type="redirect">/events/${event.ID}</result>
> </action>
>
>
> On Wed, Dec 15, 2010 at 10:05 PM, Maurizio Cucchiara <
> maurizio.cucchiara@gmail.com> wrote:
>
> > Coul...
>



-- 
Philippe Goncalves
http://www.linkedin.com/in/philippegoncalves
http://www.philippegoncalves.com
Tel: +15146326816

Re: Beans stay null

Posted by Maurizio Cucchiara <ma...@gmail.com>.
As I guess, when struts do a redirect lost your bean parameters.
Try to remove and see what happens

Maurizio Cucchiara

Il giorno 16/dic/2010 04.09, "Philippe Goncalves" <
philippe.goncalves@gmail.com> ha scritto:
Sure, here it is:

<action name="edit-event"
class="com.jivesoftware.community.ext.event.action.MyAction">
           <result name="success"
type="redirect">/events/${event.ID}</result>
           <result name="input"
type="freemarker">/plugins/event-type-plugin/resources/templates/edit-event.ftl</result>
           <result name="cancel"
type="redirect">/events/${event.ID}</result>
</action>


On Wed, Dec 15, 2010 at 10:05 PM, Maurizio Cucchiara <
maurizio.cucchiara@gmail.com> wrote:

> Coul...

Re: Beans stay null

Posted by Philippe Goncalves <ph...@gmail.com>.
Sure, here it is:

<action name="edit-event"
class="com.jivesoftware.community.ext.event.action.MyAction">
            <result name="success"
type="redirect">/events/${event.ID}</result>
            <result name="input"
type="freemarker">/plugins/event-type-plugin/resources/templates/edit-event.ftl</result>
            <result name="cancel"
type="redirect">/events/${event.ID}</result>
</action>

On Wed, Dec 15, 2010 at 10:05 PM, Maurizio Cucchiara <
maurizio.cucchiara@gmail.com> wrote:

> Could you post your struts.xml file?
>
> Maurizio Cucchiara
>
> Il giorno 16/dic/2010 04.02, "Philippe Goncalves" <
> philippe.goncalves@gmail.com> ha scritto:
> > Hi all!
> >
> > Coming from the Struts1 world, I find Struts2 really convenient!
> > But I have a simple problem, maybe I miss something. I've read some
> > tutorials about Struts2 but didn't find something... Here it is:
> >
> > I'm modifying an actual project based on struts2, spring and freemarker.
> I
> > have to add some functionnalities to a page, so I have to modify an
> Action,
> > by adding three simple pojo objects, with the getters/setters (these
> > class/variables names are fictional):
> > *
> > public class MyAction extends ActionSupport{
> >
> > private Bean bean;
> > private Bean2 bean2;
> > private Bean3 bean3;
> >
> > public Bean getBean(){
> > return bean;
> > }
> >
> > public void setBean(Bean bean){
> > this.bean = bean;
> > }
> > ...
> > }
> >
> > public class Bean{
> > private String title;
> > private String description;
> >
> > public String getTitle(){
> > return title;
> > }
> >
> > public void setTitle(String title){
> > this.title = title;
> > }
> >
> > public String getDescription(){
> > return description;
> > }
> >
> > public void setDescription(String description){
> > this.description = description;
> > }
> >
> > }*
> > *...*
> >
> > All these objects have a title and description as variables, so on my
> page,
> > I have these inputs:
> > *
> > <@s.textfield name="bean.title" />
> > <**@s.textfield** name="bean.description" />
> > ...*
> >
> > When I first print the page (input method of my action), my beans are
> well
> > filled with the values I put on the action. But when I submit the page,
> all
> > my beans stay at null (debugger on the action class)! And I don't know
> why
> > It's been one day and an half that I'm trying to get this working, but I
> > don't why my objects stay at null after the submit of my page (I've
> already
> > checked the name of my variables, trying to rename my beans, etc.)
> >
> > Could someone please tell me if I am missing something? I thought that
> with
> > struts2, you just have to declare you're objects (String, Integer, Self
> made
> > beans, etc.) on the Action with the good getters/setters and Struts take
> > care of this automatically (not like Struts1 where you have to declare
> your
> > beanform on the struts.xml).
> >
> >
> > Thanks!
> >
> > --
> > Philippe Goncalves
> > http://www.linkedin.com/in/philippegoncalves
> > http://www.philippegoncalves.com
> > Tel: +15146326816
>



-- 
Philippe Goncalves
http://www.linkedin.com/in/philippegoncalves
http://www.philippegoncalves.com
Tel: +15146326816

Re: Beans stay null

Posted by Maurizio Cucchiara <ma...@gmail.com>.
Could you post your struts.xml file?

Maurizio Cucchiara

Il giorno 16/dic/2010 04.02, "Philippe Goncalves" <
philippe.goncalves@gmail.com> ha scritto:
> Hi all!
>
> Coming from the Struts1 world, I find Struts2 really convenient!
> But I have a simple problem, maybe I miss something. I've read some
> tutorials about Struts2 but didn't find something... Here it is:
>
> I'm modifying an actual project based on struts2, spring and freemarker. I
> have to add some functionnalities to a page, so I have to modify an
Action,
> by adding three simple pojo objects, with the getters/setters (these
> class/variables names are fictional):
> *
> public class MyAction extends ActionSupport{
>
> private Bean bean;
> private Bean2 bean2;
> private Bean3 bean3;
>
> public Bean getBean(){
> return bean;
> }
>
> public void setBean(Bean bean){
> this.bean = bean;
> }
> ...
> }
>
> public class Bean{
> private String title;
> private String description;
>
> public String getTitle(){
> return title;
> }
>
> public void setTitle(String title){
> this.title = title;
> }
>
> public String getDescription(){
> return description;
> }
>
> public void setDescription(String description){
> this.description = description;
> }
>
> }*
> *...*
>
> All these objects have a title and description as variables, so on my
page,
> I have these inputs:
> *
> <@s.textfield name="bean.title" />
> <**@s.textfield** name="bean.description" />
> ...*
>
> When I first print the page (input method of my action), my beans are well
> filled with the values I put on the action. But when I submit the page,
all
> my beans stay at null (debugger on the action class)! And I don't know why
> It's been one day and an half that I'm trying to get this working, but I
> don't why my objects stay at null after the submit of my page (I've
already
> checked the name of my variables, trying to rename my beans, etc.)
>
> Could someone please tell me if I am missing something? I thought that
with
> struts2, you just have to declare you're objects (String, Integer, Self
made
> beans, etc.) on the Action with the good getters/setters and Struts take
> care of this automatically (not like Struts1 where you have to declare
your
> beanform on the struts.xml).
>
>
> Thanks!
>
> --
> Philippe Goncalves
> http://www.linkedin.com/in/philippegoncalves
> http://www.philippegoncalves.com
> Tel: +15146326816