Having trouble with wicket: Cannot Replace Component that has not been added..?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Having trouble with wicket: Cannot Replace Component that has not been added..?

Dev Vale
Hello All,

yet again another Question, I have been able to create my plugin and it works fine except for the following problem.

Global Background info regarding plugin configuration:
The plugin has it's own DocumentType called exampleDocument.
The repository contains an wicket:extention to this document, and the "root" plugin class containing this extention is Layoutexample.
The Layoutexample class is just a html file containing layout information: (wicket:id="layout.example")


So far everything works fine, when I create a new Document using the exampleDocument as type, everything works and data get's stored in the repository and such.
However the problem starts when I open a "NEW" tab with the exampleDocument type, then I get an error stating: Cannot Replace Component which has not been added: id= layout.example [MarkupContainer[Component id=layout.example].......

And this is what get's me confused, I did some googling around regading this error and so far I found the reasoning that I have a component that I have not added a component which cannot be replaced.

I am not quite sure why that message keeps coming, to add a snippet of my exampleDocument plugin class is:

 public Example(IPluginContext context, IPluginConfig config) throws RepositoryException {
        super(context, config);

JcrNodeModel ExampleD = (JcrNodeModel)Example.this.getModel;
String mode = config getString('mode');
showExample();
}


private void showExample() throws Repository Exception {
Fragment Segfragment = new Fragment("fragment", mode, this);
add(Segfragment);

if (TemplateEngine.EDIT_MODE.equals(mode)) {
     
     
        final TextArea ExampleDescripTextArea = new TextArea("descrip-textarea", new Model());
            ExampleDescripTextArea.setOutputMarkupId(true);
            ExampleDescripTextArea.setModel(new Model(getDescription));
            Segfragment.add(ExampleDescripTextArea);

            ExampleDescripTextArea.add(new OnChangeAjaxBehavior(){ private static final long serialVersionUID = 1L;

                @Override
            protected void onUpdate(AjaxRequestTarget target){
            getDescription = ExampleDescripTextArea.getDefaultModelObjectAsString();
            if (!getDescription.equals("enter description")){
             try {
                ExampleDocument.getNode().setProperty("Example:ExampleDescription", getDescription);
             }catch (Exception e){
               LOGGER.error(e.getMessage(), e);
             }
            }
            }});        

     } else {
final Label descriplabel = new Label("segdescription");
       descriplabel.setOutputMarkupId(true);
       descriplabel.setDefaultModel(new Model(getDescription));
Segfragment.add(descriplabel);


}
}
}

The example only has a textarea that obtains data from the repository and stores data in the repository (on update).
So I am at a loss, I don't understand why it keeps saying that it hasn't added the component when a 2nd tab get's opened and calls this plugin class.
Does anyone have any idea what I am missing.
If more information is needed, just let me know.
Thanx in advance,


Dev Vale
PS: When this error occures my entire CMS get's problems regarding the tabs, unable to remove tabs etc etc.


Reply | Threaded
Open this post in threaded view
|

Re: Having trouble with wicket: Cannot Replace Component that has not been added..?

Frank van Lankvelt
Hi Dev,

have you tried running wicket in development mode?  You can achieve this by setting the wicket.configuration property of the cms to 'development' (old property name: configuration).  This might give you more/earlier information as you are developing.

Some other tips on writing wicket code: set the property direcly from the model that you provide to the textarea.  The onchangeajaxbehavior is necessary because there is no form submit.  A gotcha is also that wicket will store null as a value in the model when there is no text in the input field; so you may want to replace the comparison by "enter description".equals(getDescription).

cheers, Frank

On Mon, Jul 12, 2010 at 4:46 PM, Dev Vale <[hidden email]> wrote:

Hello All,

yet again another Question, I have been able to create my plugin and it
works fine except for the following problem.

Global Background info regarding plugin configuration:
The plugin has it's own DocumentType called exampleDocument.
The repository contains an wicket:extention to this document, and the "root"
plugin class containing this extention is Layoutexample.
The Layoutexample class is just a html file containing layout information:
(wicket:id="layout.example")


So far everything works fine, when I create a new Document using the
exampleDocument as type, everything works and data get's stored in the
repository and such.
However the problem starts when I open a "NEW" tab with the exampleDocument
type, then I get an error stating: Cannot Replace Component which has not
been added: id= layout.example [MarkupContainer[Component
id=layout.example].......

And this is what get's me confused, I did some googling around regading this
error and so far I found the reasoning that I have a component that I have
not added a component which cannot be replaced.

I am not quite sure why that message keeps coming, to add a snippet of my
exampleDocument plugin class is:

 public Example(IPluginContext context, IPluginConfig config) throws
RepositoryException {
       super(context, config);

JcrNodeModel ExampleD = (JcrNodeModel)Example.this.getModel;
String mode = config getString('mode');
showExample();
}


private void showExample() throws Repository Exception {
Fragment Segfragment = new Fragment("fragment", mode, this);
add(Segfragment);

if (TemplateEngine.EDIT_MODE.equals(mode)) {


       final TextArea ExampleDescripTextArea = new
TextArea("descrip-textarea", new Model());
           ExampleDescripTextArea.setOutputMarkupId(true);
           ExampleDescripTextArea.setModel(new Model(getDescription));
           Segfragment.add(ExampleDescripTextArea);

           ExampleDescripTextArea.add(new OnChangeAjaxBehavior(){ private
static final long serialVersionUID = 1L;

               @Override
           protected void onUpdate(AjaxRequestTarget target){
           getDescription =
ExampleDescripTextArea.getDefaultModelObjectAsString();
           if (!getDescription.equals("enter description")){
            try {

ExampleDocument.getNode().setProperty("Example:ExampleDescription",
getDescription);
            }catch (Exception e){
              LOGGER.error(e.getMessage(), e);
            }
           }
           }});

    } else {
final Label descriplabel = new Label("segdescription");
      descriplabel.setOutputMarkupId(true);
      descriplabel.setDefaultModel(new Model(getDescription));
Segfragment.add(descriplabel);


}
}
}

The example only has a textarea that obtains data from the repository and
stores data in the repository (on update).
So I am at a loss, I don't understand why it keeps saying that it hasn't
added the component when a 2nd tab get's opened and calls this plugin class.
Does anyone have any idea what I am missing.
If more information is needed, just let me know.
Thanx in advance,


Dev Vale
PS: When this error occures my entire CMS get's problems regarding the tabs,
unable to remove tabs etc etc.



--
View this message in context: http://hippo.2275632.n2.nabble.com/Having-trouble-with-wicket-Cannot-Replace-Component-that-has-not-been-added-tp5283206p5283206.html
Sent from the Plugin Development and Customization mailing list archive at Nabble.com.
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Having trouble with wicket: Cannot Replace Component that has not been added..?

Dev Vale
Hey Frank,

How are you?

Thanks for the quick response, I have set the property configuration of my cms to development, however I think I need to do something else since I am running Hippo in glassfish (through netbeans).
In regards to the comparison, that could actually be completly removed, it was meant for when a user would press the save button incase of no changes to the textarea, do nothing, however I found out that the save button doesn't trigger the onchangebehavior. Thanks for pointing that out.

getDescription get's it data from the repository on load (was missing from the snippet)

/*
private String getDescription;

getDescription = ExampleD.getNode().getProperty("Example:ExampleDescription").getString();
*/

And the default value is: enter description. (as stated in the cnd)


But back to the problem at hand, the thing I don't understand is why it keeps stating that I haven't added the component, eventhou (I think I have) and why it only happens when I try to open a second document of the same custom document type.
If I close the previous document before opening a new one, no errors occure.
Thanks in advance


Dev Vale