4 Replies Latest reply: Dec 20, 2010 7:34 AM by philippe.goncalves RSS

    Struts bean

    philippe.goncalves

      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:

       

      For a plugin, I'm writing an Action class, with my methods and variables. On my Action, I have three simple pojo objects, with the getters/setters:

       

      private Bean bean;

      private Bean2 bean2;

      private Bean3 bean3;


      public Bean getBean(){

           return bean;

      }


      public void setBean(Bean bean){

      this.bean = bean;

      }

      ...

       

      All these objects have a title and description as variables, so on my ftl, I have these inputs:

      <input name="bean.title" />

      <input name="bean.description" />

      ...

       

      When I first print the page (input method of my action), my input are well filled with the value I put on the action. But when I submit the page, all my beans stay at null! And I don't know why

       

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

       

      Thanks!

        • Re: Struts bean
          Aaron Johnson

          Could you post the full Java / FTL code here?

           

          AJ

            • Re: Struts bean
              philippe.goncalves

              Hi Aaron, I don't think I can post all the code because it's a private project (Actually, I'm modifying one of your commercial plugin) but here is the partial code:

               

              ftl:

              <@s.textfield name="bean.title" />  

               

              Java action:

              public class testAction{


                  protected Bean bean;


                  public Bean getBean() {
                      return bean;
                  }


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


              ...

              }

               

              Java pojo:

              public class Bean{


                   private String title;

                   private String description;


                   public String getDescription() {
                      return description;
                  }


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


                  public String getTitle() {
                      return title;
                  }


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


                  public Bean() {
                  }


              }

               

              Thanks

            • Re: Struts bean
              philippe.goncalves

              Found my problem, for those who got the same, you have to override the acceptableParameterName method from JiveActionSupport.