I have created a stateless component in Wicket 1.5, by extending the component and giving the #StatelessComponent annotation,
I was trying to check the component being stateful/stateless with the StatelessChecker.
But i am not able to check, here is the code which i was trying .
#StatelessComponent
public class StatelessText extends TextField
//Client Class
StatelessText test = new StatelessText("test");
StatelessChecker sc = new StatelessChecker();
sc.onBeforeRender(test);
I dont see anything on console or any exceptions/errors.
Maybe i am not using the correct way, Can anybody please guide me here.
Appreciate the Help.
you have to register the StatelessChecker during the init of the WicketApplication.
/**
* #see org.apache.wicket.Application#init()
*/
#Override
public void init() {
super.init();
// might want to check if you're in dev mode or not...
getComponentPreOnBeforeRenderListeners().add(new StatelessChecker());
}
You dont need to explicitly call the Statelesschecker in your class. As Throsten said you need to add that in your WebApplications init and annotate your - class to be checked - as Statelesscomponent. If your Application is confidured to be in development mode in you web.xml you will get a runtime error when calling this page if it is Statefull.
Im not sure I understood what you are trying to do there. why are you holding an instance of your class in itself? are you trying to build a singleton? And what purpose does StatelessText has anyway? the Textfield in an usual form will be Stateless as long theres no explicitly added Ajax behaviour to it.
Related
I have a Wicket application and I'm trying to implement separate configuration that can be changed remotely. That's the end goal, anyway.
What I'm trying to do is set up Cayenne to work by starting it manually, rather than using the web.xml file. I have tried a bunch of different things, but I'm not sure I fully understand how the context is applied to all threads.
I have tried creating a ServerRuntime in my Application class. I've also tried on my custom BasePage class that each page uses. I can get it to kind of work by doing the following on the BasePage, but it is inconsistent:
public class BasePage ....
public static ServerRuntime runtime = new ServerRuntime("cayenne-config.xml");//This is in my BasePage class, but I've also tried this in the Application class
#Override
protected void init() {
BaseContext.bindThreadObjectContext(Application.runtime.getContext());//This is in my BasePage class
}
Like I said, that kind of works, but it isn't consistent. I keep getting errors on
BaseContext.getThreadObjectContext();
Error is this:
java.lang.IllegalStateException: Current thread has no bound ObjectContext.
I can't seem to find much information on this. I tried doing stuff like this, and accessing the runtime using these as well, but nothing is working consistently.
WebUtil.setCayenneRuntime(this.getServletContext(), runtime);
BaseContext.bindThreadObjectContext(WebUtil.getCayenneRuntime(((Application)getApplication()).getServletContext()).getContext());
Any help would be greatly appreciated.
I figured out a way to do this on my own.
I'm extending CayenneFilter and overriding the init method.
In there I copied nearly their exact code. I will be able to check for any config here and load the proper xml file. This obviously isn't the ironed out solution, but is definitely a step forward, and could be the way I end up doing this.
Either way, here's what I have tested to be working.
#WebFilter(filterName = "cayenne-config", displayName = "cayenne-config", urlPatterns = {"/*"})
public class TestFilter extends CayenneFilter
{
#Override
public void init(FilterConfig config) throws ServletException
{
this.checkAlreadyConfigured(config.getServletContext());
this.servletContext = config.getServletContext();
WebConfiguration configAdapter = new WebConfiguration(config);
Collection modules = configAdapter.createModules(new Module[]{new WebModule()});
ServerRuntime runtime = new ServerRuntime("cayenne-test.xml", (Module[])modules.toArray(new Module[modules.size()]));
WebUtil.setCayenneRuntime(config.getServletContext(), runtime);
}
}
I don't think the annotation is needed (I am specifying it all in the web.xml file), but I thought I would leave it here so you could see that it is changing.
If I could find a way to change the config (FilterConfig) values (the init parameters), then I could just change that to the name of the xml file I want to use and not override this entire method. I couldn't figure out how to do that, but I'll look further later.
If anyone has another better answer, I would love to hear it.
in my controller, I need to choose what service implementation I need to use on spring. Before I was encapsulating this code in a factory, but I think that its not a good practice...
#Component
public class StoreServiceFactory {
#Autowired
private List<StoreService> storeServices;
public StoreService getService(){
if(isActiveSale){
return storeServices.get("PublicStoreService")
}
return storeServices.get("PrivateStoreService")
}
}
So I would like to encapsulate this behaviour to not care about inside my controller.. How can I get it??
If isActiveSale changes when the application is running, I think that what you got is a good solution. Since the Controller is a singleton you can't expect a different injection everytime this value changes.
If you get the value only on the startup of the application(e.g. from some property) you can use a profile.
There is nothing wrong with a factory, although as #R4J points out in the comments it is more of a provider, since it doesn't instantiate anything. I would consider the factory/provider a good choice if the 'isActiveSale' status changes based on things outside of the current control flow, like a configuration in a property file. A setting set in some adminstration screen, or maybe based on the time of day.
I'm trying to use AOP with picocontainer.
so far I found in the documentation:
http://picocontainer.codehaus.org/interception.html
pico = new DefaultPicoContainer();
pico.as(INTERCEPT).addComponent(Apple.class, BraeburnApple.class);
and then create the interceptor, but looking through the code, I cannot find the INTERCEPT property anywhere.
as receives a Properties value, which pico implements in Characteristics class.
anyone has a clue, or has implemented it before and knows how to keep with it?
Thanks
looks like the property for this Behavior is somehow missing in this pico version, check org.picocontainer.Characteristics in older versions, I really hope it was implemented somewhere :)
Also there's old styled way for interception in pico: http://www.markhneedham.com/blog/2008/11/11/logging-with-pico-container/
Since the 2.14.3 org.picocontainer.behaviors still have these classes, I suppose this way is ok
This worked for me. First, create a proxy by extending a bean:
public static class ChangeMapInfoEndpointInterceptor extends MapInfoRoutingManagementBean {
#Override
public void setEndpoint(String endpoint) {
System.out.println("setEndpoint called");
}
}
Then pass it to the intercepting-styled container:
MutablePicoContainer context = new PicoBuilder().withBehaviors(new Intercepting()).build();
context.addComponent(MapInfoRoutingManagement.class, MapInfoRoutingManagementBean.class);
Intercepted intercepted = context.getComponentAdapter(MapInfoRoutingManagement.class).findAdapterOfType(Intercepted.class);
intercepted.addPostInvocation(MapInfoRoutingManagement.class, new ChangeMapInfoEndpointInterceptor());
I've got an Eclipse RCP application and a strange behaviour while using a wizard page. Following situation:
I've got a wizard page which is part of a multi-page-wizard. At this page I override the createContent(...) method to create my widgets, etc. After creating my widgets 2 private methods addListeners() and init() are called which initializes my widgets out of the model and add some listeners (e.g. a ModifyListener). The obscure behaviour is the following: When I first call init() and after that call addListeners() everything works fine. But if I do it the vice versa I got a NullPointerException in the WizardDialog.updateButtons() method which is part of RCP framework: There is a variable called currentPage as the following code excerpt shows. This variable causes the NPE mentioned above. If I do it the right way, the variable is correctly set.
...
if (backButton != null) {
backButton.setEnabled(currentPage.getPreviousPage() != null);
}
...
I don't get this behaviour. Can someony explain it to me? Within the 2 private methods mentioned above no framework-calls are done. Maybe it's some timing issue?
Best regards,
AnarchoEnte
I'm setting the timeout when initializing the webservice stub and I'm even logging it using getTimeout() before making the call to make sure it's set but the call completes regardless of the timeout value set. Is it possible this is a bug or am I missing something here?
Below is my code doing this:
proxy = new DCPControllerWSPortTypeProxy();
proxy.setEndpoint(endpoint);
((Stub)proxy.getDCPControllerWSPortType()).setTimeout(120000);
To fix the problem, you will have to add the following class wherever you want in your project. When I had a similar problem, I have declared it as a private class in the same class where I'm instantiating my stub. (I'm currently using Axis 2 )
private class CustomNetworkClient extends sun.net.NetworkClient
{
public CustomNetworkClient(int readTimeout)
{
defaultSoTimeout = readTimeout;
}
}
After doing that, you could add the following line in your code, which will set the timeout.
CustomNetworkClient client = new CustomNetworkClient(SOAP_READ_TIMEOUT);
Or you could simply do the following, since you don't really need the object that's being created:
new CustomNetworkClient(SOAP_READ_TIMEOUT)
This has been reported as a bug before, where connection timeouts and read timeouts are not being set when using HTTPS connections : http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4700777
The following link helped me figure out this workaround:
http://www.noizeramp.com/article.php?article=se-networking_specifics_under_Java_Web_Start
I hope this will help you somehow =)