You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Ludwig <ge...@gmail.com> on 2011/10/04 04:21:26 UTC

beanedit form issues (the FAQ seems to be incorrect)

I've got a bean that reads/writes to the file system. To do that, it's
constructor takes a param for the file path. Very straightforward, however
using this bean has been problematic. I got the "no service implements the
interface String" exception when constructing the bean, which led me to the
FAQ here: http://tapestry.apache.org/beaneditform-faq.html However, things
do not work as advertised in the FAQ.

No matter what I do, Tapestry requires that the bean have a no argument
constructor, and that I annotate that constructor with @Inject. And in the
debugger I see that the parameterized constructor is called twice
from onPrepareFromMyBeanEditor(), after which the no-param constructor is
called.

At the time the page renders, my bean lacks a filepath, I assume because the
last time the constructor was called, it had no parameters.

Summary:
Bean constructors are called multiple times, twice with params and once
without, always resulting in a bean that has been created with no
parameters.

What can I do here? I've included hacked version of the FAQ code with notes.

Best,

George

public class MyBean {
  @Inject           <------------------------------ without this annotation
on the no-param constructor, Tapestry always throws a "no service ..."
exception
  public MyBean() { ... }
  public MyBean(String filePath) { ... }
}

public class MyPage {
 @Property
 public MyBean myBean;  <--------------- the example code declares this as
public, but Tapestry throws an exception, insisting it be made private...is
this possibly related to the problem I'm seeing?
 void onPrepareFromMyBeanEditor() {
   myBean = new MyBean(getFilePath()); <------------------- I need a param
to point to the file, but can't seem to hang on to the bean that is
instantiated here
 }
}

Re: beanedit form issues (the FAQ seems to be incorrect)

Posted by George Ludwig <ge...@gmail.com>.
Josh,

I'm on Tapestry 5.2.6

I just tried to recreate this issue, and was unable, so it must have
been me (working too late some nights).

However, the onPrepareFromMyBeanEditor() method is still called twice,
which seems inefficient. onActivate() is only called once, so I'm
going to leave the bean instantiation code there, at least for now.

-George

On Tue, Oct 4, 2011 at 4:01 PM, Josh Canfield <jo...@gmail.com> wrote:
> "This occurs when the BeanEditForm's object parameter is bound to null"
>
> Looking at the code, it seems that it only calls the constructor if
> your "object" parameter is null.
>
> Can you provide some of the actual template/project code or a small
> example project that reproduces the problem?
>
> Also, I may have overlooked it, but what version of tapestry are you using?
>
> Josh
>
> On Mon, Oct 3, 2011 at 7:21 PM, George Ludwig <ge...@gmail.com> wrote:
>> I've got a bean that reads/writes to the file system. To do that, it's
>> constructor takes a param for the file path. Very straightforward, however
>> using this bean has been problematic. I got the "no service implements the
>> interface String" exception when constructing the bean, which led me to the
>> FAQ here: http://tapestry.apache.org/beaneditform-faq.html However, things
>> do not work as advertised in the FAQ.
>>
>> No matter what I do, Tapestry requires that the bean have a no argument
>> constructor, and that I annotate that constructor with @Inject. And in the
>> debugger I see that the parameterized constructor is called twice
>> from onPrepareFromMyBeanEditor(), after which the no-param constructor is
>> called.
>>
>> At the time the page renders, my bean lacks a filepath, I assume because the
>> last time the constructor was called, it had no parameters.
>>
>> Summary:
>> Bean constructors are called multiple times, twice with params and once
>> without, always resulting in a bean that has been created with no
>> parameters.
>>
>> What can I do here? I've included hacked version of the FAQ code with notes.
>>
>> Best,
>>
>> George
>>
>> public class MyBean {
>>  @Inject           <------------------------------ without this annotation
>> on the no-param constructor, Tapestry always throws a "no service ..."
>> exception
>>  public MyBean() { ... }
>>  public MyBean(String filePath) { ... }
>> }
>>
>> public class MyPage {
>>  @Property
>>  public MyBean myBean;  <--------------- the example code declares this as
>> public, but Tapestry throws an exception, insisting it be made private...is
>> this possibly related to the problem I'm seeing?
>>  void onPrepareFromMyBeanEditor() {
>>   myBean = new MyBean(getFilePath()); <------------------- I need a param
>> to point to the file, but can't seem to hang on to the bean that is
>> instantiated here
>>  }
>> }
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: beanedit form issues (the FAQ seems to be incorrect)

Posted by Josh Canfield <jo...@gmail.com>.
"This occurs when the BeanEditForm's object parameter is bound to null"

Looking at the code, it seems that it only calls the constructor if
your "object" parameter is null.

Can you provide some of the actual template/project code or a small
example project that reproduces the problem?

Also, I may have overlooked it, but what version of tapestry are you using?

Josh

On Mon, Oct 3, 2011 at 7:21 PM, George Ludwig <ge...@gmail.com> wrote:
> I've got a bean that reads/writes to the file system. To do that, it's
> constructor takes a param for the file path. Very straightforward, however
> using this bean has been problematic. I got the "no service implements the
> interface String" exception when constructing the bean, which led me to the
> FAQ here: http://tapestry.apache.org/beaneditform-faq.html However, things
> do not work as advertised in the FAQ.
>
> No matter what I do, Tapestry requires that the bean have a no argument
> constructor, and that I annotate that constructor with @Inject. And in the
> debugger I see that the parameterized constructor is called twice
> from onPrepareFromMyBeanEditor(), after which the no-param constructor is
> called.
>
> At the time the page renders, my bean lacks a filepath, I assume because the
> last time the constructor was called, it had no parameters.
>
> Summary:
> Bean constructors are called multiple times, twice with params and once
> without, always resulting in a bean that has been created with no
> parameters.
>
> What can I do here? I've included hacked version of the FAQ code with notes.
>
> Best,
>
> George
>
> public class MyBean {
>  @Inject           <------------------------------ without this annotation
> on the no-param constructor, Tapestry always throws a "no service ..."
> exception
>  public MyBean() { ... }
>  public MyBean(String filePath) { ... }
> }
>
> public class MyPage {
>  @Property
>  public MyBean myBean;  <--------------- the example code declares this as
> public, but Tapestry throws an exception, insisting it be made private...is
> this possibly related to the problem I'm seeing?
>  void onPrepareFromMyBeanEditor() {
>   myBean = new MyBean(getFilePath()); <------------------- I need a param
> to point to the file, but can't seem to hang on to the bean that is
> instantiated here
>  }
> }
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: beanedit form issues (the FAQ seems to be incorrect)

Posted by George Ludwig <ge...@gmail.com>.
Muhammad,

Thanks for the reply! I did clean an rebuild the project. Also, I used
the event handler onPrepareFromMyBeanEditor() method, and as I wrote
in my original post, my bean is instantiated twice with parameters,
and is finally instantiated one more time without parameters.

No matter what I did using the approaches described in the FAQ,
Tapestry forced a no-param constructor.

Another list member wrote to me off-list and suggested I simply
instantiate the bean in the onActivate() method. I did that, and now
everything works: the constructor is called exactly once with the
proper parameters.

Which leaves me still wondering what exactly is going on with the
examples in the FAQ!

-George


On Tue, Oct 4, 2011 at 2:38 PM, Muhammad Gelbana <m....@gmail.com> wrote:
> 2 Suggestions:
>
> 1. Have you tried cleaning your project and re-building it ? Restarting the
> server on which you are developing ?
> 2. Why don't you construct the bean yourself ? Add an event handler method
> to handle the "PREPARE" event of form embracing your bean editor.
>
> On Tue, Oct 4, 2011 at 4:21 AM, George Ludwig <ge...@gmail.com>wrote:
>
>> I've got a bean that reads/writes to the file system. To do that, it's
>> constructor takes a param for the file path. Very straightforward, however
>> using this bean has been problematic. I got the "no service implements the
>> interface String" exception when constructing the bean, which led me to the
>> FAQ here: http://tapestry.apache.org/beaneditform-faq.html However, things
>> do not work as advertised in the FAQ.
>>
>> No matter what I do, Tapestry requires that the bean have a no argument
>> constructor, and that I annotate that constructor with @Inject. And in the
>> debugger I see that the parameterized constructor is called twice
>> from onPrepareFromMyBeanEditor(), after which the no-param constructor is
>> called.
>>
>> At the time the page renders, my bean lacks a filepath, I assume because
>> the
>> last time the constructor was called, it had no parameters.
>>
>> Summary:
>> Bean constructors are called multiple times, twice with params and once
>> without, always resulting in a bean that has been created with no
>> parameters.
>>
>> What can I do here? I've included hacked version of the FAQ code with
>> notes.
>>
>> Best,
>>
>> George
>>
>> public class MyBean {
>>  @Inject           <------------------------------ without this annotation
>> on the no-param constructor, Tapestry always throws a "no service ..."
>> exception
>>  public MyBean() { ... }
>>  public MyBean(String filePath) { ... }
>> }
>>
>> public class MyPage {
>>  @Property
>>  public MyBean myBean;  <--------------- the example code declares this as
>> public, but Tapestry throws an exception, insisting it be made private...is
>> this possibly related to the problem I'm seeing?
>>  void onPrepareFromMyBeanEditor() {
>>   myBean = new MyBean(getFilePath()); <------------------- I need a param
>> to point to the file, but can't seem to hang on to the bean that is
>> instantiated here
>>  }
>> }
>>
>
>
>
> --
> *Regards,*
> *Muhammad Gelbana
> Java Developer*
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: beanedit form issues (the FAQ seems to be incorrect)

Posted by Muhammad Gelbana <m....@gmail.com>.
2 Suggestions:

1. Have you tried cleaning your project and re-building it ? Restarting the
server on which you are developing ?
2. Why don't you construct the bean yourself ? Add an event handler method
to handle the "PREPARE" event of form embracing your bean editor.

On Tue, Oct 4, 2011 at 4:21 AM, George Ludwig <ge...@gmail.com>wrote:

> I've got a bean that reads/writes to the file system. To do that, it's
> constructor takes a param for the file path. Very straightforward, however
> using this bean has been problematic. I got the "no service implements the
> interface String" exception when constructing the bean, which led me to the
> FAQ here: http://tapestry.apache.org/beaneditform-faq.html However, things
> do not work as advertised in the FAQ.
>
> No matter what I do, Tapestry requires that the bean have a no argument
> constructor, and that I annotate that constructor with @Inject. And in the
> debugger I see that the parameterized constructor is called twice
> from onPrepareFromMyBeanEditor(), after which the no-param constructor is
> called.
>
> At the time the page renders, my bean lacks a filepath, I assume because
> the
> last time the constructor was called, it had no parameters.
>
> Summary:
> Bean constructors are called multiple times, twice with params and once
> without, always resulting in a bean that has been created with no
> parameters.
>
> What can I do here? I've included hacked version of the FAQ code with
> notes.
>
> Best,
>
> George
>
> public class MyBean {
>  @Inject           <------------------------------ without this annotation
> on the no-param constructor, Tapestry always throws a "no service ..."
> exception
>  public MyBean() { ... }
>  public MyBean(String filePath) { ... }
> }
>
> public class MyPage {
>  @Property
>  public MyBean myBean;  <--------------- the example code declares this as
> public, but Tapestry throws an exception, insisting it be made private...is
> this possibly related to the problem I'm seeing?
>  void onPrepareFromMyBeanEditor() {
>   myBean = new MyBean(getFilePath()); <------------------- I need a param
> to point to the file, but can't seem to hang on to the bean that is
> instantiated here
>  }
> }
>



-- 
*Regards,*
*Muhammad Gelbana
Java Developer*