I have a wicket page like this:
public final class Services extends WebPage {
public Services() {
super();
}
public Services(PageParameters params) {
StringValue serviceType = params.get("name");
if("report".equals(serviceType.toString())) {
this.getResponse().write("HelloWorld");
}
}
}
and it's html is empty.
when I call URL of this page I see this error
Index: 0, Size: 0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:604)
at java.util.ArrayList.get(ArrayList.java:382)
at java.util.Collections$UnmodifiableList.get(Collections.java:1211)
at org.apache.wicket.markup.Markup.get(Markup.java:130)
at org.apache.wicket.Component.internalRender(Component.java:2356)
at org.apache.wicket.Component.render(Component.java:2307)
at org.apache.wicket.Page.renderPage(Page.java:1010)
at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:121)
at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:271)
at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:165)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282)
...
i don't know really what is wrong in my simple wicket page.
Wicket ever expects some markup in the associated HTML template to the code. The line that is the originator of your Exception is in Component.class see
private final void internalRender()
{
...
MarkupElement elem = markup.get(0);
...
}
That code gets a 'root' element of the associated markup. A code without any markup is a non-sence in Wicket.
TIP: If you just want to handle a request, mount a shareable resource or some of other resources other then a page.
Related
I'm currently trying to test a ListView on android with Espresso, with a custom ArrayAdapter.
Here is the test :
final AssociationsListActivity listActivity = getActivity();
final Association association1 = new Association(ASSOCIATION_NAMES[0], ASSOCIATION_DESCRIPTIONS[0]);
final Association association2 = new Association(ASSOCIATION_NAMES[1], ASSOCIATION_DESCRIPTIONS[1]);
final Association association3 = new Association(ASSOCIATION_NAMES[2], ASSOCIATION_DESCRIPTIONS[2]);
listActivity.addAssociation(association1);
listActivity.addAssociation(association2);
listActivity.addAssociation(association3);
assertTrue(listActivity.getAssociationsList().size() == 3);
onView(withId(R.id.associationsListView)).check(matches(isDisplayed()));
onData(anything())
.inAdapterView(withId(R.id.associationsListView))
.atPosition(0)
.perform(click());
assertCurrentActivityIsInstanceOf(AssociationsListActivityTest.this
, AssociationsPageActivity.class);
The method listActivity.addAssociation(association); simply does associationArrayAdapter.add(association);.
The ArrayAdapteris used to add elements to a ListView(visible by default) with the id R.id.associationsListView
When I run this test, I get the following error :
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view.
Expected: is displayed on the screen to the user
Got: "ListView{id=2131427414, res-name=associationsListView, visibility=VISIBLE, width=996, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=42.0, y=42.0, child-count=0}"
Which is caused by the following assertion, onView(withId(R.id.associationsListView)).check(matches(isDisplayed()));
Also when commenting this assertion, the next one causes the following exception :
android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'with id: ch.epfl.sweng.project:id/associationsListView'.
...
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
(is assignable from class: class android.widget.AdapterView and is displayed on the screen to the user)
Target view: "ListView{id=2131427414, res-name=associationsListView, visibility=VISIBLE, width=996, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=42.0, y=42.0, child-count=0}"
I went through a lot of stack overflow threads covering those exception, I replaced those tests by other equivalents but those errors still show up I don't know what to do! Thanks for any help!
I found what was wrong!
My method to add elements to the ArrayAdapter used runOnUIThread but it seems that the test was not waiting for this method, thus the associationsListViewwas considered as not displayed to the user ! So I fixed my method listActivity.addAssociation(Association association) like this :
public void addAssociation(final Association association) {
final CountDownLatch latch = new CountDownLatch(1);
runOnUiThread(new Runnable() {
#Override
public void run() {
if (!associationList.contains(association)) {
associationArrayAdapter.add(association);
}
latch.countDown();
}
});
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!associationList.contains(association)) {
associationList.add(association);
}
}
All parts of the test now pass :)
i'm using Xsoup.
this is the code:
private void updateSeed(Document document) {
mappingParser
.setSeed(Xsoup.compile("//div[#class='pgCell'][last()]/a/#href")
.evaluate(document).get());
}
when i execute the previous function i'm getting the following exception:
Exception in thread "main" org.jsoup.select.Selector$SelectorParseException: Could not parse query 'div[#class='pgCell'][last()]': unexpected token at 'last()'
at us.codecraft.xsoup.xevaluator.XPathParser.byFunction(XPathParser.java:225)
at us.codecraft.xsoup.xevaluator.XPathParser.consumePredicates(XPathParser.java:202)
at us.codecraft.xsoup.xevaluator.XPathParser.findElements(XPathParser.java:138)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:51)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:375)
at us.codecraft.xsoup.xevaluator.XPathParser.combinator(XPathParser.java:85)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:49)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:375)
at us.codecraft.xsoup.Xsoup.compile(Xsoup.java:27)
at com.qannoufit.test.CrawlerController.updateSeed(CrawlerController.java:102)
at com.qannoufit.test.CrawlerController.populateShouldParse(CrawlerController.java:91)
at com.qannoufit.test.CrawlerController.startCrawling(CrawlerController.java:60)
at com.qannoufit.test.Main.main(Main.java:12)
Try to use a CSS selector instead. The initial xPath query could be translated like below:
div.pgCell:last-of-type > a
Once you have the anchor, gets its href.
private void updateSeed(Document document) {
Element anchor = document.select("div.pgCell:last-of-type > a").first();
if (anchor==null) {
// Anchor not found, handle error here...
}
mappingParser.setSeed(anchor.absUrl("href"));
}
When the multiple trees in the view expanded (Expand the selected tree), the following error is thrown.
I couldnot find out what exactly throws this error. this is the stack trace i got after exception,
org.eclipse.swt.SWTError: No more handles
at org.eclipse.swt.SWT.error(SWT.java:4109)
at org.eclipse.swt.SWT.error(SWT.java:3998)
at org.eclipse.swt.SWT.error(SWT.java:3969)
at org.eclipse.swt.widgets.Display.internal_new_GC(Display.java:2589)
at org.eclipse.swt.graphics.Image.getImageData(Image.java:1371)
at org.eclipse.swt.internal.ImageList.set(ImageList.java:401)
at org.eclipse.swt.internal.ImageList.add(ImageList.java:66)
at org.eclipse.swt.widgets.Tree.imageIndex(Tree.java:3636)
at org.eclipse.swt.widgets.TreeItem.setImage(TreeItem.java:1686)
at org.eclipse.jface.viewers.TreeViewerRow.setImage(TreeViewerRow.java:166)
at org.eclipse.jface.viewers.ViewerCell.setImage(ViewerCell.java:169)
at org.eclipse.jface.viewers.WrappedViewerLabelProvider.update(WrappedViewerLabelProvider.java:166)
at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:152)
at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:934)
at org.eclipse.jface.viewers.AbstractTreeViewer$UpdateItemSafeRunnable.run(AbstractTreeViewer.java:102)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:1014)
at org.eclipse.jface.viewers.StructuredViewer$UpdateItemSafeRunnable.run(StructuredViewer.java:481)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.StructuredViewer.updateItem(StructuredViewer.java:2141)
at org.eclipse.jface.viewers.AbstractTreeViewer.createTreeItem(AbstractTreeViewer.java:829)
at org.eclipse.jface.viewers.AbstractTreeViewer$1.run(AbstractTreeViewer.java:804)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren(AbstractTreeViewer.java:778)
at org.eclipse.jface.viewers.TreeViewer.createChildren(TreeViewer.java:644)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalExpandToLevel(AbstractTreeViewer.java:1714)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalExpandToLevel(AbstractTreeViewer.java:1724)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalExpandToLevel(AbstractTreeViewer.java:1724)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalExpandToLevel(AbstractTreeViewer.java:1724)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalExpandToLevel(AbstractTreeViewer.java:1724)
at org.eclipse.jface.viewers.AbstractTreeViewer.expandToLevel(AbstractTreeViewer.java:1056)
at org.eclipse.jface.viewers.AbstractTreeViewer.expandToLevel(AbstractTreeViewer.java:1037)
at org.eclipse.jface.viewers.AbstractTreeViewer.expandAll(AbstractTreeViewer.java:1026)
at com.rockwellcollins.rccase.tarbuilder.actions.ExpandAllAction.run(ExpandAllAction.java:44)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at com.rockwellcollins.rccase.Application.start(Application.java:74)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
at org.eclipse.equinox.launcher.Main.main(Main.java:1384)
//Label Provider for that tree
public class ViewTreeLabelProvider extends LabelProvider implements
IColorProvider, IBaseLabelProvider,IFontProvider{
#Override
public Image getImage(Object element) {
if (element instanceof EObject) {
return aa.getImages(element);
}
return super.getImage(element);
}
}
// for loading image
public class aa {
public static Image getImages(Object element) {
if (element instanceof ClassA) {
return ClassA.getimage();
} else if (element instanceof ClassB) {
return ClassB.getimage();
} else if (element instanceof ClassC) {
return ClassC.getimage();
} else if (element instanceof ClassD) {
return ClassD.getimage();
}
return null;
}
}
My project code base is vast, i could not share it completely. So, i wrote the snippet in the simple way to convey the problem.
Actually, the images are placed in the icons folder and are fetched by AbstractUIPlugin.imageDescriptorFromPlugin(plugin, path), which inturn stores the images in the Image registry.
I also noticed that, this may be due to the limit in the GDI Objects in the Windows registry.
After the 10000 GDI objects limit is reached the exception is thrown.
By default for Windows 7, GDIProcessHandleQuota value is 10,000. When I googled , I found that, the value can be set to maximum of 65,536.
I have tried to by increasing the GDIProcessHandleQuota from 10,000 to 65,000. Still the same exception is thrown, but after reaching 19,932 GDIObjects.
I anticipate that, the problem may be due to improper disposal of GDIObjects and the exception is thrown in the Image.class.
Suggestions please!!
In your ClassA.getimage(), ClassB.getimage() ... make sure to not create an image each time ".getimage()" is called, cache it.
private Image image;
public Image getImage() {
if ( image == null) {
image = new Image(Display.getDefault(), "");
}
return image;
}
Since it seems that you are in an Eclipse environment, better even use "org.eclipse.jface.resource.ImageRegistry".
Where "UIPlugin" is your plugin extending "org.eclipse.ui.plugin.AbstractUIPlugin".
If you don't have one, create one and add it to your MANIFEST.MF (Bundle-Activator: YOURCLASS).
public Image getImage() {
String key = getClass().getName();
ImageRegistry imageRegistry = UIPlugin.getDefault().getImageRegistry();
Image image = imageRegistry.get(key);
if (image == null) {
image = new Image(Display.getDefault(), "");
imageRegistry.put(key, image);
}
return image;
}
i am trying to put a video inside my jsp page, dynamically, like:
<video id="myVideo" width="420" height="345" controls="controls">
<source src="#{detailsBean.ref.videoLink}" type="video/ogg" /> </video>
But I get this error : org.apache.jasper.JasperException: /details.jsp(64,29) #{..} is not allowed in template text
What should i use instead?
package beans;
import dto.Referinta;
public class DetailsBean
{
Referinta ref = new Referinta( );
public Referinta getRef ( )
{
return ref;
}
public void setRef ( Referinta ref )
{
this.ref = ref;
}
}
I dont think that the problem is in the bean, it's about the tag, can't find one to use with dynamic src. This will work if in src i put the direct link to the video.
I use the <p:media> to display static PDF content.
<p:media value="/resource/test.pdf"
width="100%" height="300px" player="pdf">
</p:media>
How can I change it to display dynamic content?
Like as in <p:graphicImage>, the value attribute can point to a bean property returning StreamedContent. This only requires a special getter method for the reasons which is explained in detail in the following answer on using <p:graphicImage> with a dynamic resource from a database: Display dynamic image from database with p:graphicImage and StreamedContent.
In your particular example, it would look like this:
<p:media value="#{mediaManager.stream}" width="100%" height="300px" player="pdf">
<f:param name="id" value="#{bean.mediaId}" />
</p:media>
With
#ManagedBean
#ApplicationScoped
public class MediaManager {
#EJB
private MediaService service;
public StreamedContent getStream() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
// So, we're rendering the HTML. Return a stub StreamedContent so that it will generate right URL.
return new DefaultStreamedContent();
} else {
// So, browser is requesting the media. Return a real StreamedContent with the media bytes.
String id = context.getExternalContext().getRequestParameterMap().get("id");
Media media = service.find(Long.valueOf(id));
return new DefaultStreamedContent(new ByteArrayInputStream(media.getBytes()));
}
}
}