wicket AjaxLink onclick not responding - ajax

I'm building a website with wicket. I have a modal window that opens from an ajaxlink from the main page. The problem is that when I added a CSS to my HTML code in order to make it more visible attractive, it stopped working. So now, when I click in the AjaxLink that opens the modal window, nothing happens and I can't figure out why. Any Ideas??
This is the code of the AjaxLink:
AjaxLink privacyLink = new AjaxLink<Void>("privacylink") {
#Override
public void onClick(AjaxRequestTarget target) {
// TODO Auto-generated method stub
modal2.show(target);
}
};
One more comment. This AjaxLink is introduced as a part of a ListView, so actually there are multiple AjaxLinks.

In order for the AjaxLink to refresh you will need to call something along the lines of:
modal2.setVisible(true);
target.addComponent(modal2Container);
Where modal2 is the component that you want to control the visibility of, and modal2Container is a WebMarkupContainer with .setOutputMarkupId(true) that modal2 is added to when the page/panel is constructed.
I have found the examples at http://www.wicket-library.com/wicket-examples-1.4.x/ajax/ to be particularly useful (I'm using 1.4, but there are other examples for whichever version of wicket you are running you can get to from http://wicketstuff.org/).

I finally found the solution!!, It was a problem of the version of jQuery that I was using (1.4.2) so I just changed it to 1.5.2 and it worked!

Related

Previously working (in 1.4.7) Apache Wicket 6 DataView not updating when data source SortableDataProvider is updated from a ModalWindow

As the title says, I am trying to update a web app to a more recent Apache Wicket version. The problem is very like this one here, albeit the link is very old (and an ancient version of Wicket, which is not what I'm using)
http://users.wicket.apache.narkive.com/tG6XOAUM/refresh-page-after-form-submit-within-modalwindow
So what I do is:
- display a DataView in a regular page, populated using a SortableDataProvider
- create a panel inside a ModalWindow to make some data changes;
- on onSubmit (using an AjaxFallbackButton) inside this panel, insert a new item into the same SortableDataProvider which I use to populate my DataView
- I then call "target.add(wmc)" on the WebMarkupContainer surrounding my DataView
- my DataView.populateItem registers the change when I add trace code, but the change is not actually displayed ie the screen is apparently not being refreshed.
If I do the same thing from an AjaxFallbackButton.onSubmit() NOT inside a ModalWindow, but in the same WebPage as my DataView, then all is well and I see the change on the page immediately.
I started to upgrade to Wicket 8 but there is so much else to change that I'd rather not do this right now.
I can post code if needs be but I wondered if anyone had come across this problem. As I say, fine in Wicket 1.4.7. Next step would be to create a mini-app to demonstrate this, I guess, which might well lead me to a solution anyway but hoping for some good input from that Wicket community out there ;-)
You're holding a reference from one page to another:
public class TestBugInsertItemPage extends WebPage {
private TestBugPage parent;
This not allowed in Wicket, and I wonder how this has worked in 1.4.
Your trying to update components from another window, that cannot work:
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
TestBugInsertItemPage.this.parent.dp.addLine();
target.add(TestBugInsertItemPage.this.parent.wmc);
TestBugInsertItemPage.this.parent.modal.close(target);
}
An AjaxRequestTarget is valid for a single request for a single page only.
You should use a ModelWindow with a panel instead.
Update for your second example:
Passing a panel to a different page won't make a difference. Wicket serializes pages to disk, thus you cannot share any state between them.
You should use a modal dialog with a panel instead:
TestBugPage.this.modal.setContent(TestBugPage.this.myPanel);
Now TestBugPage and your panel reside in the same component hierarchy, they communicate with each other and both can be updated on the same Ajax request.

wicket: how to update a form component with ajax, not the whole form

I've got a wicket dropdown choice, and when I select something, I want to update some components within the form. This is working fine using wicket (1.4) ajax. However, it's updating the whole form including the dropdownchoice itself. There are quite a lot of items in the dropdown list (maybe 2000) so it's not great from a performance point of view.
Here's the page hierarchy:
form (Form)
|----packageDDC (DropDownChoice)
|----pptview (RefreshingView)
|----buy (Button)
packageDDC.add(new AjaxFormComponentUpdatingBehavior("onchange") {
protected void onUpdate(AjaxRequestTarget target) {
//--snip-- update pricepoints which back up the pptview
target.addComponent(form); //ie the form
}
}
In the ajax debug window I can see all the dropdown choice options being re-sent every time
What I want to do is only update the pptview and the Button via ajax, not the contents of the dropdownchoice.
I tried adding pptview to the target, but it complains that RefreshgViews can't be updated via ajax.
I tried wrapping the pptview with an EnclosureContainer, but wicket didn't like that either (something about setRenderBodyOnly)
So I tried using an WebMarkupContainer (called 'pptcontainer') and setting pptview to be a child of that - but now the pptview is not updated. Instead it says (in Ajax debug):
"ERROR: Wicket.Ajax.Call.processComponent: Component with id [[purchaseButton2f]] was not found while trying to perform markup update. Make sure you called component.setOutputMarkupId(true) on the component whose markup you are trying to update."
"ERROR: Wicket.Ajax.Call.processComponent: Component with id [[pptcontainer2e]] was not found while trying to perform markup update. Make sure you called component.setOutputMarkupId(true) on the component whose markup you are trying to update."
well these objects definitely do have this set to true:
buy.setOutputMarkupId(true);
pptcontainer.setOutputMarkupId(true);
pptcontainer.setOutputMarkupPlaceholderTag(true);
So the page is not updated correctly.
What am I doing wrong?
The new hierarchy is:
form (Form)
|----packageDDC (DropDownChoice)
|----pptcontainer (WebMarkupContainer)
| |----pptview (RefreshingView)
|----buy (Button)
I faced same problem with popup window which content is provided by ajax call. In my case the problem was solved by changing html placeholder "wicket:container" to "div" element as proposed in this article: http://sha.nnoncarey.com/blog/archives/36
After this change generated html has correct id and wicket do not have problem to find it and replace content with AJAX response.

How do I add ajax behavior to a dynamically created component in a backing bean?

In respose to Infragile's request in another thread, I am asking this as a separate question rather than a followup.
Here is the problem I am attempting to address:
I'm migrating from JSF1.2 to JSF2. Everything worked fine in JSF1.2.
I have rewritten a critical item to be a composite component which is basically a panel created in my backing bean by adding components in code.
In particular, I have h:inputText and h:selectOneMenu components that I create in code along with an "Apply" h:commandButton.
The "Apply" button has an action listener that checks for the values in the h:inputText and h:selectOneMenu components. All this works fine, but when I fetch the values in the h:inputText or h:selectOneMenu components I get the original values, not the new values that were entered by the user. Like I said, this worked fine in JSF1.2 (i got the new values), but not in JSF2 for some reason.
I have tried several things to get around this that haven't worked, so I figured I would add ajax behavior to the h:inputText and h:selectOneMenu items and when the values in these components change, I could call another backing bean listener for the ajax behavior to fetch the new values.
I am trying to add ajax behavior to a component I create in code (not bound to a page component). I can create the component with no problem. However, the problem that I am having is how to add the ajax behavior to the component.
Could someone post sample code to add an ajax behavior for a value change or blur event? Here is the code I use to create the component in code - how would I need to modify it to add the ajax behavior?
hpg = new HtmlPanelGrid();
children = hpg.getChildren();
children.clear();
....
input = new HtmlInputText();
....
children.add(input);
What code would I have to add to replace the "add ajax behavior here" line, and what would the arguement for the listener method be (arguement for the method to replace the ????? below)?
public void myAjaxListener(?????) { ...... {
I have been trying to get a handle on this for some time now. I feel that I am pretty close, but don't know the syntax I need. I can provide more information on how I am fetching the component Ids and searching for the values in my action listener if that will help.
Thanks
This is how you can add dynamically AjaxBehaviorListener to yor component:
...
HtmlInputText inpuText = new HtmlInputText();
AjaxBehavior blurBehavior = new AjaxBehavior();
blurBehavior.addAjaxBehaviorListener(new BlurListener());
blurBehavior.setTransient(true);
inputText.addClientBehavior("blur", blurBehavior)
...
public class BlurListener implements AjaxBehaviorListener {
public BlurListener() {
}
#Override
public void processAjaxBehavior(AjaxBehaviorEvent event) {
// do your job
HtmlInputText inputText = event.getComponent(); // your input text component
...
}
}
"blur" represents event when this listener will be triggered. Remember that JSF Component must support this event, otherwise it won't work.
(Here you can see under covers and how to build custom AJAX component http://weblogs.java.net/blog/driscoll/archive/2009/10/09/jsf-2-custom-java-components-and-ajax-behaviors?force=670 )
However in your case I think problem is that buttons ActionListener is triggered before actual component values are submited. You can solve it by moving your ActionListener logic to button action, by aformentioned AJAX, maybe by findinng actual values in UIComponents (HtmlInputText, UISelectOne), not sure but immediate attribute can also influence it.

how Remove A Control From Ajax Mode Inside A Repeater?

I am using radajaxmanager for getting ajax mode.
But many times I prefer to remove a control such as a link button inside a repeater from ajax mode (means repeater has been added to radajaxmanager).
How can I do this job with radajaxmanager?
That control goes in the right way and it is not appeared in the radajaxmanager configuration, and we only have repeater there.
we should use OnRequestStart event (client-side) of RadAjaxManager like below :
function OnRequestStart(s, e) {
if (e.get_eventTarget() == 'bla') {
e.set_enableAjax(false);
}
}
A more comprehensive set of examples on how to specifically exclude a control can be found in the Telerik documentation here:
http://www.telerik.com/help/aspnet-ajax/ajax-exclude.html

Eclipse RCP: How can I update a view when the selected editor changes?

This should be quite a common problem, but I couldn't find anything helpful on the topic.
We are developing an application with Eclipse RCP. The application shows data in an editor of which usually multiple instances are open. In an additional view you can edit the editor-values. When the values are changed in the view they are updated in the editor and it's dirty flag is set.
So far it works fine. What we're missing is: When another editor instance gets the focus, our view should show the data of this editor.
I managed to do that for two views. The second view is sucessfully updated using a TableViewer as selection Provider and registering a SelectionListener in the other view. I tried the same thing for the editor using a Viewer I subclassed from ContentViewer, but it didn't work.
Can this approach be working?
Or do I need a different approach on the problem?
May be you can subclass your view from PageBookView and then provide special adapter for your editor. Outline View is implemented using this approach.
Thank you cerealk, that was exactly what I needed. :-)
Update the View when another Editor is selected
public class myView {
// Create an IPartListener2
IPartListener2 pl = new IPartListener2() {
// If the Editor I'm interested in was updated ...
public void partActivated(IWorkbenchPartReference ref) {
IWorkbenchPart part = ref.getPart(true);
if (part instanceof DetailEditor) {
// ... update the view
Contact contactFromSelectedEditor = ((DetailEditor) part).detailComposite.contact;
detailComposite.update(contactFromSelectedEditor);
}
}
...
}
// Add the IPartListener2 to the page
IWorkbenchPage page = this.getSite().getPage();
page.addPartListener(pl);
}
Why use an IPartListener2 instead of an IPartListener
The IPartListener2 replaces IPartListener with 3.5.
As explained in this this answer:
You should always use IPartListener2 as it can handle part-change events on parts that have not yet been
created because they are hidden in a stack behind another part.
This
listener will also tell you when a part is made visible or hidden or
when an editor's input is changed.

Resources