I want to do something based on the model change, e.g. if user enters text in the Text SWT widget, I would like to do something based on that. But the problem is, if I use e.g. key listener on the widget, it will get called before the data binding process occurs and therefore the behaviour would'nt be consistent. One way around this is to do the logic inside the binding process, but this is not really a convinient way of handling this problem. Suggestions?
So basically, what I need is an event listener, which is triggered after the data binding occures (on some specified widget of course).
Use an IChangeListener to listen for changes on the model observable value. This will be called after the model has been updated from the target.
Something like:
IObservableValue targetOV = WidgetProperties.text(SWT.Modify).observe(text control);
IObservableValue modelOV = PojoProperties.value("your field").observe(object);
bindContext.bindValue(targetOV, modelOV);
modelOV.addChangeListener(change listener);
Related
I need to listen to a HZ update event ONLY when an specific property of the object changes:
https://docs.hazelcast.com/imdg/4.1/data-structures/map#listening-to-map-entries-with-predicates
But I dont know if this could be done through a Predicate (see bold fragment):
map.addEntryListener(chatsWithConvView, Predicates.sql(""), true);
If the property stays the same, and all other properties of the object changes I dont want the event to be triggered because of millions of events would be trigered.
Is this possible?
Unfortunately, this doesnt work, but could be something like this:
map.addEntryListener(chatsWithConvView,
Predicates.sql("waConversationsCounter = (SELECT
'waConversationsCounter' + 1)"), true);
I know this waConversationsCounter is always going to increment 1 (always), is the only update event I want to capture. But this predicate doesnt work.
How can I do it?
I have a form that contains a text field input that is bound to a field in a model object. When a user enters data into that text field it can affect multiple other fields/components within the form based on calculations. My business logic is encapsulated in a service layer.
Theoretically the way I want this to work is that when the user updates the field, an ajax call is made to the server (on keypress) where the logic from the service is applied and all affected fields are updated on the model object. Once the model has been updated on the server, I want to sync the current state of the model object to the screen.
Is the only way to do this to refresh the entire screen? Is there a way to re-render only the components bound to the fields in the model that have changed? Also, if I refresh the screen, the field that is being edited is updated as well, is there a way to exclude this?
I am interested in any best practices for this technique.
Thanks
I assume from your tags that you're using wicket. Wicket uses Behaviors for this purpose. In the following example you will update both DropDownChoices if the input of the TextField changed. You just need to add those controls to the AjaxRequestTarget. Models of both DropDownChoices will be reloaded and rerendered at the frontend. Also make sure to call setOutputMarkupId(true) on controls you want to update.
TextField<String> textField = new TextField<String>("input");
Component dropDownA = new DropDownChoice<>("dropA").setOutputMarkupId(true);
Component dropDownB = new DropDownChoice<>("dropB").setOutputMarkupId(true);
textField.add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1478280524536023725L;
#Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(dropDownA);
target.add(dropDownB);
}
});
With Ajax you can update any Component you want, just make sure it has markup id (Component.setOutputMarkupId(true)).
You need to use AjaxFormComponentUpdatingBehavior or AjaxFormChoiceComponentUpdatingBehavior and in its onUpdate() callback you have to update the models of the respective FormComponents and then you can use FormComponent.this.getForm().visitChildren(FormComponent.class, IVisit) to visit all FormComponents of the current Form and add to AjaxRequestTarget only the ones you have updated.
Update
Another good solution (even better!) is to use Wicket Event bus. In the Ajax behavior you could broadcast an event:
component.send(getForm(), Broadcast.BREADTH, new UIChangedEvent(target, newValue));
where UIChangedEvent is your own class/POJO that brings the new value of the updated component and the AjaxRequestTarget.
Then the other FormComponents could override #onEvent() and use the value to calculate their new value and use the target to update themselves or not, depending on the earlier calculation.
I want to create a Swing JTextPane that takes action when the user types text into it. But I also want to be able to alter the text in that pane without it treating that alteration as a user typing. How can I do this?
If you don't let update events fire, then chances are that your UI won't get updated either, depending on the actual implementation. So I agree that you might be better off by talking to the event handler, letting it know that the next alteration is going to be a programmatic change. Something like this:
try {
listener.setProgrammaticChange(true);
// change document
}
finally {
listener.setProgrammaticChange(false);
}
I have a JXTree and I'd like to add searching to it this way:
As the user types, the model returns the matching elements of the tree and selects the first one of the set in the tree's view.
The problem is, that by default the JXTree has an other keylistener, that selects an element starting with the currently typed letter.
Sometimes the native listener fires last making the outcome wrong. What can be done to prevent this behavior? I don't want to remove the inherent listener because it has arrow based navigation... (Which I have to reimplement.)
I've already read this: Is the order in which KeyListeners will be called guaranteed?, but I don't think that I can create the proposed listener wrapper without great effort, since BasicTreeUI's Handler class is private.
That's not a feature of JXTree but JTree. Overriding JTree#getNextMatch() to always return null should disable the JTree selection on key press.
Here's the sit:
I have a JSF component which is basically a list of 'documents'
I have any number of document viewer components on the same page.
None of these components "know" about each other. In other words, they cannot be configured at design time to link to each other or anything like that.
When the user clicks a document link I wish each one of the document viewer components to be notified.
Basically the idea would be to have the document viewers publish the fact that they listen for a certain type of event ("DocumentSelectedEvent" say) which the doc list component would fire.
I can think of ways of doing this that are not JSF specific, but I'm wondering if the JSF event model can handle that sort of thing.
Anyone have any ideas?
I don't think there's a way of doing that with the standard JSF event model.
Is there any way you can bind the components to a backing bean? That way when an event happens you can just go through your list of components and notify each of them.
You need to just bind the components with a backing bean and use a ValueChangeListener to notify the backing bean. The listener method could change the state of the other components which are tied to respective UI components.
Are you trying to do it in a "Ajax" way without page being explicitly submitted?
ValueChangeEvent
I do not know how you implemented your document list but if it were say a dropdown or any other multi item list component you can do an Value Change Event and force a submit on change for the component. Then in the page code backing bean you can call the methods for your viewers to load whatever you like.
In your jsf you just specify the value change handler you wrote in the backing bean.
/**
* Handle document click value change.
*
* #param valueChangedEvent the value changed event
*/
public void handleDocumentSelect(ValueChangeEvent valueChangedEvent) {
String selectedDocument = valueChangedEvent.getNewValue();
doDocViewer1DisplayMethod(selectedDocument);
doDocViewe2DisplayMethod(selectedDocument);
}
Modify your jsf tag to use your new value change event handler and force the submit.
<f:componentTag
attr=xxx
attr=xxx
valueChangeListener="#{pc_BackingBean.handleDocumentSelect}"
onChange=submit();>