[groovy-user] groovy wicket please tell me the problem

10 views
Skip to first unread message

fachhoch

unread,
Oct 5, 2010, 12:39:55 PM10/5/10
to us...@groovy.codehaus.org

here is my groovy file


package gov.hhs.acf.web.util;


import java.util.ArrayList;
import java.util.List;


import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.IMarkupResourceStreamProvider;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.StringResourceStream;


class UserMenuItems implements MenuItems {


List<Component> components ;


void myInit(){
components= new ArrayList<Component>();
components.add (new OMBCircularPanel());
components.add (new SendComments());
}

@Override
public List<Component> getComponents() {
myInit();
return components;
}


private abstract class CustomPanel extends Panel implements
IMarkupResourceStreamProvider{
public CustomPanel() {
super(MenuItems.menuItemId);
}
public IResourceStream getMarkupResourceStream(MarkupContainer
container,Class<?> containerClass){
return new StringResourceStream(getMarkUp());
}

protected abstract String getMarkUp();
}

private class OMBCircularPanel extends CustomPanel {
public OMBCircularPanel() {
super();
}
@Override
protected String getMarkUp() {
return """
<wicket:panel>

http://www.whitehouse.gov/sites/default/files/omb/assets/a133/a133_revised_2007.pdf
A-133 OMB Circular
</wicket:panel>
""";
}
}

private class SendComments extends CustomPanel {
public SendComments() {
super();
}
@Override
protected String getMarkUp() {
return """
<wicket:panel>
mailto:comm...@gmail.com Send Comments
</wicket:panel>
""";
}
}

}

this is a simple class creating some wicket panels .

When I call getComponents , I get this exception

Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at
gov.hhs.acf.web.util.UserMenuItems$OMBCircularPanel.<init>(UserMenuItems.groovy:48)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at
org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at
org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:107)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:52)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:192)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:200)
at gov.hhs.acf.web.util.UserMenuItems.myInit(UserMenuItems.groovy:24)
at gov.hhs.acf.web.util.UserMenuItems$myInit.callCurrent(Unknown Source)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:147)
at
gov.hhs.acf.web.util.UserMenuItems.getComponents(UserMenuItems.groovy:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(LazyInitProxyFactory.java:416)
at org.apache.wicket.proxy.$Proxy142.getComponents(Unknown Source)
at gov.hhs.acf.web.pages.common.BasePage.basePageInit(BasePage.java:164)
at gov.hhs.acf.web.pages.common.BasePage.<init>(BasePage.java:60)
at gov.hhs.acf.web.pages.common.HomePage.<init>(HomePage.java:40)
... 48 more

please somebody help me what is the error referring to, I donot have any
method called init I tried debugger and noticed the exception is thrown
before it reaches super class constructor
--
View this message in context: http://groovy.329449.n5.nabble.com/groovy-wicket-please-tell-me-the-problem-tp3199941p3199941.html
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Roshan Dawrani

unread,
Oct 5, 2010, 2:37:08 PM10/5/10
to us...@groovy.codehaus.org
With which groovy version do u get this error?

fachhoch

unread,
Oct 5, 2010, 3:42:47 PM10/5/10
to us...@groovy.codehaus.org

Paul King

unread,
Oct 5, 2010, 6:04:12 PM10/5/10
to us...@groovy.codehaus.org
On 6/10/2010 5:42 AM, fachhoch wrote:
>
> with 1.7.2

And which version of wicket?

Paul.

Paul King

unread,
Oct 5, 2010, 6:32:48 PM10/5/10
to us...@groovy.codehaus.org
On 6/10/2010 5:42 AM, fachhoch wrote:
>
> with 1.7.2

<init> is the constructor.

Running below on trunk in the GroovyConsole (i.e. not a web container)
fails as per the message below. I am not familiar with the wicket
lifecycle but it certainly seems to be getting to the super constructor
and the error not unreasonable given I haven't got a web container
in place.

Paul.


//////////////////////////
@Grab('org.apache.wicket:wicket:1.4.9')
@Grab('org.slf4j:slf4j-jdk14:1.6.1')


import org.apache.wicket.Component
import org.apache.wicket.MarkupContainer
import org.apache.wicket.markup.IMarkupResourceStreamProvider

import org.apache.wicket.markup.html.panel.Panel
import org.apache.wicket.util.resource.IResourceStream
import org.apache.wicket.util.resource.StringResourceStream

interface MenuItems { String menuItemId = 'dummy' }

class UserMenuItems implements MenuItems {

List<Component> components

void myInit(){
components = [new OMBCircularPanel(), new SendComments()]
}

List<Component> getComponents() {
myInit()
return components
}

private abstract class CustomPanel extends Panel implements IMarkupResourceStreamProvider {
public CustomPanel() {
super(MenuItems.menuItemId)
}

IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass){


return new StringResourceStream(getMarkUp())
}
protected abstract String getMarkUp()
}

private class OMBCircularPanel extends CustomPanel {
public OMBCircularPanel() {
super()
}

protected String getMarkUp() {
return """
<wicket:panel>
http://www.whitehouse.gov/sites/default/files/omb/assets/a133/a133_revised_2007.pdf
A-133 OMB Circular
</wicket:panel>
"""
}
}

private class SendComments extends CustomPanel {
public SendComments() {
super()
}

protected String getMarkUp() {
return """
<wicket:panel>
mailto:comm...@gmail.com Send Comments
</wicket:panel>
"""
}
}
}

println new UserMenuItems().components
//////////////////////////

produces this result:

org.apache.wicket.WicketRuntimeException: There is no application attached to current thread Thread-17
at org.apache.wicket.Application.get(Application.java:179)
at org.apache.wicket.Component.getApplication(Component.java:1323)
at org.apache.wicket.Component.<init>(Component.java:920)
at org.apache.wicket.MarkupContainer.<init>(MarkupContainer.java:113)
at org.apache.wicket.markup.html.WebMarkupContainer.<init>(WebMarkupContainer.java:49)
at org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup.<init>(WebMarkupContainerWithAssociatedMarkup.java:51)
at org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup.<init>(WebMarkupContainerWithAssociatedMarkup.java:43)
at org.apache.wicket.markup.html.panel.Panel.<init>(Panel.java:76)
at UserMenuItems$CustomPanel.<init>(ConsoleScript14:27)
...

fachhoch

unread,
Oct 5, 2010, 9:38:55 PM10/5/10
to us...@groovy.codehaus.org

wicket version 1.4.8

that error is from wicket becasue, Components cannot be instanaited without
an Application instantiated .

it is supposed to be called after Application is instantiated.

I call the getComponents method inside a page (this means Applciation is
instantiated),
the same code works when I make it .java why is it not working with groovy
?

--
View this message in context: http://groovy.329449.n5.nabble.com/groovy-wicket-please-tell-me-the-problem-tp3199941p3200687.html


Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------

fachhoch

unread,
Oct 6, 2010, 11:06:16 AM10/6/10
to us...@groovy.codehaus.org

the code works when I make it .java and does not work with .groovy , I want
this as groovy becasue I want to dynamically load MenuItems and chaange
them without restarting the server , please help me wicket -groovy gurus
--
View this message in context: http://groovy.329449.n5.nabble.com/groovy-wicket-please-tell-me-the-problem-tp3199941p3201589.html

Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------

fachhoch

unread,
Oct 7, 2010, 10:45:42 PM10/7/10
to us...@groovy.codehaus.org

I changed the code

instead of using OMBCircularPanel I changed it to

Panel panel= new CustomPanel(){


protected String getMarkUp() {return """
<wicket:panel>

http://www.whitehouse.gov/sites/default/files/omb/assets/a133/a133_revised_2007.pdf
A-133 OMB Circular
</wicket:panel>

"""};
}


and then call components.add (panel); and the code works without any
problems

--
View this message in context: http://groovy.329449.n5.nabble.com/groovy-wicket-please-tell-me-the-problem-tp3199941p3203983.html


Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages