Inside a legacy application, i am creating a new class MyForm, and modify the existing class MyPanel by adding a reference to MyForm:
import com.smartgwt.client.widgets.layout.VLayout;
public class MyPanel extends VLayout
{
public static MyForm myForm = null;
public MyPanel() {
myForm = new MyForm();//the line causing trouble
}
}
and:
public class MyForm extends com.smartgwt.client.widgets.Window
{
private static TextItem myTextItem;
public MyForm()
{
//other lines of code
myTextItem.setValue("some value");
}
}
When commenting the initialization of MyForm, the application works as it did before; when i uncomment this line, the application hangs out. The main page of the application is loading forever.
There are no compiler warnings displayed in my IDE (Eclipse), also no error logs/stack trace appear in the log files of the server (Apache Tomcat).
However, the browser console displays the following warning:
*11:55:42.978:WARN:Log:Uncaught exception escaped: com.google.gwt.core.client.JavaScriptException (TypeError) : Cannot
read property 'oq' of null
at new JEb(ra-0.js)
at xHb(ra-0.js)
at new EHb(ra-0.js)
at iFb(ra-0.js)
at UFb(ra-0.js)
at XFb(ra-0.js)
at aA(ra-0.js)
at nd(ra-0.js)
at Id(ra-0.js)
at eval(ra-0.js)
at Gb(ra-0.js)
at Jb(ra-0.js)
at eval(ra-0.js)
GWT version: 2.8.0
Tomcat version: 8.0
Related
When I use the Playwright's codegen feature it traces my clickpath into a Java file. But the created file has the wrong syntax, so I can't compile it.
I start the codegen with:
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="codegen wikipedia.org"
And the inspector provides this code:
public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions()
.setHeadless(false));
BrowserContext context = browser.newContext();
page.navigate("https://en.wikipedia.org/wiki/Main_Page");
page.getByPlaceholder("Search Wikipedia").click();
page.getByPlaceholder("Search Wikipedia").fill("stackoverflow");
page.getByRole("button", new Page.GetByRoleOptions().setName("Go")).click();
assertThat(page).hasURL("https://en.wikipedia.org/wiki/Stack_Overflow");
}
}
}
But there is already the first error. The method getByRole requires an AriaRole as its first parameter, not a String. So it's easy to fix, but I think it's not the idea of the product to generate code and let the developer fix it.
In some YouTube tutorials the inspector generates only fill and click functions with powerful selectors inside.
Is there a way to change the generated output to a specifc "code-style"? Or is there another reason why other people get nice working code and I don't?
My dependency:
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.27.0</version>
</dependency>
Sorry if I am wrong. But you should get something like this from an inspector which compiles fine
package org.example;
import com.microsoft.playwright.*;
import com.microsoft.playwright.options.*;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
import java.util.*;
public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions()
.setHeadless(false));
BrowserContext context = browser.newContext();
// Open new page
Page page = context.newPage();
// Go to https://www.wikipedia.org/
page.navigate("https://www.wikipedia.org/");
// Click input[name="search"]
page.locator("input[name=\"search\"]").click();
// Fill input[name="search"]
page.locator("input[name=\"search\"]").fill("stackoverflow");
// Click button:has-text("Search")
page.locator("button:has-text(\"Search\")").click();
assertThat(page).hasURL("https://en.wikipedia.org/wiki/Stack_Overflow");
}
}
}
When the rtu.smallview.xhtml action event is triggered it requests info from the java bean, from the database select and hands it back to the xhtml.
The xhtml was not displaying the data from the database, so I added breakpoints in the java bean to figure out what was going wrong, but when the program loaded it never hit the breakpoint in the bean.
The server output is saying this when the program is loaded:
Info: WELD-000119: Not generating any bean definitions from Beans.RTU.RTU_SmallView_Bean because of underlying class loading error: Type pojo.rtu.RTU_unit not found. If this is unexpected, enable DEBUG logging to see the full error.
So I stopped the server, clean and built the project again, and when it runs for the first time it loads the bean, the information is retrieved and displayed. Though if I clean and build the project again, when it runs the second time it displays the same WELD-000119 error.
I copy and pasted just the code to make the RTU section run to a new project and the server doesn't ever throw this error, and it works every time the bean is requested and every time the server is started.
Edit 1:
When I restart NetBeans and Clean and Build the project after it starts it says this:
Note: C:\Users\Administrator\Documents\NetBeansProjects\OIUSA_1\src\java\Beans\RTU\RTU_SmallView_Bean.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
This is the only java class it says this about, so here is the code I used for that class:
package Beans.RTU;
import Database.RTU.RTU_SmallView_Select;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import pojo.rtu.RTU_unit;
/**
*
* #author Administrator
*/
#Named(value = "rtu_SmallView_Bean")
#RequestScoped
public class RTU_SmallView_Bean {
public RTU_SmallView_Bean() {
try {
RTU_SmallView_Select selectData;
selectData = new RTU_SmallView_Select();
this.smallViewList = selectData.getData();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
List<RTU_unit> smallViewList = new ArrayList();
String unit_type;
int unit_number;
String rig_name;
String location_name;
public List<RTU_unit> getSmallViewList() {
return smallViewList;
}
public void setSmallViewList(List<RTU_unit> smallViewList) {
this.smallViewList = smallViewList;
}
public String getUnit_type() {
return unit_type;
}
public void setUnit_type(String unit_type) {
this.unit_type = unit_type;
}
public int getUnit_number() {
return unit_number;
}
public void setUnit_number(int unit_number) {
this.unit_number = unit_number;
}
public String getRig_name() {
return rig_name;
}
public void setRig_name(String rig_name) {
this.rig_name = rig_name;
}
public String getLocation_name() {
return location_name;
}
public void setLocation_name(String location_name) {
this.location_name = location_name;
}
}
My project structure is as follows:
Sources:
Beans.RTU.RTU_SmallView_Bean.java
Database.RTU.RTU_SmallView_Select.java
pojo.rtu.RTU_unit.java
Webpages:
rtu.rtu_smallview.xhtml
I am thinking it has something to do with the actual server, but I'm not sure where to start looking for this error. If you would like to see the actual code for the beans and what not, let me know and I'll edit the question with all the code. Thanks
Problem has been solved, the file RTU_Unit.java was in a folder called pojo.rtu. I deleted the folder, made it again with a new name pojo.rtus, refactored the file RTU_Unit.java for the new folder and the problem has gone away.
I'm trying to access a simple java code from inside my C# webapp using jni4net, but it is throwing some errors.
Generated all proxies and dlls to access the java class.
I wrote the code for connecting with JVM inside the 'Program.cs' file.
Later on the custom java function ie. display_msg() is called from the testfunc() which can be called from anywhere inside the bot using Program.testfunc().
I'm attaching the Program.cs file and the exception occurring.
Also I've named my java file as Test.java and it's inside package mypack.
Program.cs
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using net.sf.jni4net;
using System;
using mypack;
namespace ValidationBot
{
public class Program
{
public static void Main(string[] args)
{
var setup = new BridgeSetup();
setup.Verbose = true;
setup.AddAllJarsClassPath("./");
Bridge.CreateJVM(setup);
Bridge.RegisterAssembly(typeof(Test).Assembly);
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureLogging((logging) =>
{
logging.AddDebug();
logging.AddConsole();
}).UseStartup<Startup>();
public static void testfunc()
{
Test test = new Test();
test.display_msg();
Console.WriteLine("\nPress any key to quit.");
Console.ReadKey();
}
}
}
Test.java
package mypack;
import java.io.*;
public class Test
{
public static void main(String args[])
{
int s =10;
System.out.println(s);
}
public void display_msg()
{
System.out.println("Hello, I'm inside a java program");
}
}
Exception
Exception thrown: 'System.MissingMethodException' in jni4net.n-0.8.8.0.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in System.Private.CoreLib.dll
Exception thrown: 'System.TypeInitializationException' in jni4net.n-0.8.8.0.dll
An unhandled exception of type 'System.TypeInitializationException' occurred in jni4net.n-0.8.8.0.dll
The type initializer for 'net.sf.jni4net.utils.Registry' threw an exception.
I'm a beginner to C# so please help me out with this.
From the comments we deduced that .NET core 2.1 does not support this method: (and maybe others)
System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)
Attempting to implement the same sort of Event and EventBus stuff that's in the Dashboard demo, I'm getting this error when I try to run the app:
=================================================================
Vaadin is running in DEBUG MODE.
Add productionMode=true to web.xml to disable debug features.
To show debug window, add ?debug to your application URL.
=================================================================
Aug 31, 2015 3:06:08 PM com.vaadin.server.DefaultErrorHandler doDefault
SEVERE:
java.lang.NoClassDefFoundError: com/google/common/eventbus/SubscriberExceptionHandler
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2472)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:854)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1274)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
at info.chrismcgee.sky.scheduling.SchedulingUI.<init>(SchedulingUI.java:48)
Line 48 in SchedulingUI.java is:
private final SchedulingEventBus schedulingEventbus = new SchedulingEventBus();
(I've mostly just replaced all the "Dashboard" references to "Scheduling" to conform with my web app.) Of course, it doesn't help that I am still trying to figure out the point of SchedulingEvent.java and SchedulingEventBus.java and how they work. (Still a newbie.)
EDIT 09/01/2015: For clarification about what I renamed, here is my SchedulingEventBus.java file:
package info.chrismcgee.sky.event;
import info.chrismcgee.sky.scheduling.SchedulingUI;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.SubscriberExceptionContext;
import com.google.common.eventbus.SubscriberExceptionHandler;
/**
* A simple wrapper for Guava event bus. Defines static convenience methods for
* relevant actions.
*
* #author Marketing
*
*/
public class SchedulingEventBus implements SubscriberExceptionHandler {
private final EventBus eventBus = new EventBus(this);
public static void post(final Object event) {
SchedulingUI.getSchedulingEventbus().eventBus.post(event);
}
public static void register(final Object object) {
SchedulingUI.getSchedulingEventbus().eventBus.register(object);
}
public static void unregister(final Object object) {
SchedulingUI.getSchedulingEventbus().eventBus.unregister(object);
}
#Override
public void handleException(final Throwable exception,
final SubscriberExceptionContext context) {
exception.printStackTrace();
}
}
Add the following dependency to the ivy.xml file:
<dependency org="com.google.guava" name="guava" rev="18.0"/>
I was having the exact same problem trying to do the exact same thing. This cleared up the NoClassDefFoundError.
So, I've spent a couple of hours first trying to "fix" this myself and then Googling like a madman but didn't find anything that would've helped so now I'm here.
Basically I have a custom Panel within Wicket's own ModalWindow and since I like unit testing, I want to test it. The specific behavior here is refreshing the ModalWindow's content: In my actual code from where I extracted this the Ajax event handling actually reloads new stuff to the content panel, I just removed those to make this shorter.
So, here's the Panel's code
package wicket.components;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.*;
public class MyModalWindowPanel extends Panel {
private Form form;
private ModalWindow modal;
public MyModalWindowPanel(String id, ModalWindow modal) {
super(id);
this.setOutputMarkupId(true);
this.modal = modal;
initializeForm();
addBasicDataFieldsToForm();
add(campaignForm);
}
private void initializeForm() {
form = new Form("form");
form.setOutputMarkupId(true);
}
private void addBasicDataFieldsToForm() {
campaignForm.add(new AjaxButton("infoSubmit",
new Model<String>("Ajaxy Click")) {
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
modal.setContent(new MyModalWindowPanel(modal.getContentId(),
modal));
modal.show(target);
}
});
}
}
and the corresponding markup
<wicket:panel>
<form wicket:id="form">
<input type="submit" value="Ajaxy Click" wicket:id="infoSubmit" />
</form>
</wicket:panel>
Do note that when run in servlet container such as Tomcat, this works correctly - there's no functional bugs here!
So what's the problem then? I'm not seemingly able to get the unit test for this to work! My test class for the panel looks like this
package wicket.components;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.util.tester.*;
import junit.framework.TestCase;
public class MyModalWindowPanelTestCase extends TestCase {
private WicketTester tester;
private ModalWindow modal;
#Override
protected void setUp() throws Exception {
tester = new WicketTester();
modal = new ModalWindow("modal");
tester.startPanel(new TestPanelSource() {
public Panel getTestPanel(String id) {
return new MyModalWindowPanel(id, modal);
}
});
}
public void testReloadingPanelWorks() throws Exception {
// the next line fails!
tester.executeAjaxEvent("panel:campaignForm:campaignInfoSubmit",
"onclick");
tester.assertNoErrorMessage();
}
}
and here's the resulting stacktrace of running that
java.lang.IllegalStateException: No Page found for component [MarkupContainer [Component id = modal]]
at org.apache.wicket.Component.getPage(Component.java:1763)
at org.apache.wicket.RequestCycle.urlFor(RequestCycle.java:872)
at org.apache.wicket.Component.urlFor(Component.java:3295)
at org.apache.wicket.behavior.AbstractAjaxBehavior.getCallbackUrl(AbstractAjaxBehavior.java:124)
at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.getCallbackScript(AbstractDefaultAjaxBehavior.java:118)
at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.getCallbackScript(AbstractDefaultAjaxBehavior.java:106)
at org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow$WindowClosedBehavior.getCallbackScript(ModalWindow.java:927)
at org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.getWindowOpenJavascript(ModalWindow.java:1087)
at org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.show(ModalWindow.java:352)
at wicket.components.MyModalWindowPanel$1.onSubmit(MyModalWindowPanel.java:45)
at org.apache.wicket.ajax.markup.html.form.AjaxButton$1.onSubmit(AjaxButton.java:102)
at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(AjaxFormSubmitBehavior.java:143)
at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:177)
at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:299)
at org.apache.wicket.util.tester.BaseWicketTester.executeAjaxEvent(BaseWicketTester.java:1236)
at org.apache.wicket.util.tester.BaseWicketTester.executeAjaxEvent(BaseWicketTester.java:1109)
at wicket.components.MyModalWindowPanelTestCase.testReloadingPanelWorks(MyModalWindowPanelPanelTestCase.java:31)
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 junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
So, how can/should I fix my unit test so that it would pass?
I'm gonna go out on a limb here and say: Add your Panel component to a Page for testing..
AFAIK you can't test individual components, but should set up a test by getting a page and doing asserts on that..
This is what I use for testing:
public class TestHomePage {
private static WicketTester tester;
#BeforeClass
public static void setUp() {
tester = new WicketTester(new WicketApplication() {
#Override
protected void init() {
//Override init to use SpringUtil's SpringContext due to missing WebApplicationContext
addComponentInstantiationListener(new SpringComponentInjector(this, SpringUtil.getContext()));
}
});
}
#Test
public void testRenderMyPage() {
//start and render the test page
tester.startPage(HomePage.class);
//assert rendered page class
tester.assertRenderedPage(HomePage.class);
//assert page contents
tester.assertContains("Welcome to my webpage");
}
}
Please do correct me if I'm wrong!
The "production" code shown that ostensibly works is inconsistent. I suspect the variable campaignForm is supposed to be the field form.
But I think the root problem is that the modal window itself is nowhere actually attached to a component, and thus cannot be rendered.
If in the real code, it's attached somewhere outside your MyModalWindowPanel component, you'll definitely need to attach it somewhere in the test as well, likely by making your test build either a test page or a test panel that contains both the modal window and the component under test.
The only time I've gotten that "No Page Found" exception was when trying to call getPage() in a panel constructor. The constructor is executed before the panel gets added to a page, so nothing is found... Are you perhaps doing something like that? Perhaps this code works in production, but is still throwing that error behind the scenes?
I know it's not what you are looking for, but I've found Selenium to be a great tool for testing web UI's. JUnit is awesome for testing logic, but Selenium is better suited for making sure the right thing displays in your UI. It looks hinky with it's gui interface and such, but it works great, and if you dig a bit the scripting api is easily accessible.