How to get the name of previous page in ZK? - zk

I have a list page where it has button menu. While i select a record and click on that button menu a new page will be open with the corresponding code from the selected record.
From the opened page's doAfterCompose, how can i get the name of the previous page from where we clicked the button and opened the new page?
Please anyone help me with this...

What you should do (although I haven't seen your code) is to generate an event that passes as a value the previous page number when 'that button menu' is clicked. The event will then be picked up by the event queue together with the passed value.
So inside the method that handles the event generated by the click of the button menu you should add the following:
EventQueues.lookup("myqueue", EventQueues.DESKTOP, true)
.publish(new Event("buttonClicked", null, previousPage));
where previousPage is the value passed (an integer for the sake of the example).
Then inside the doAfterCompose() method you extrapolate the data passed:
EventQueues.lookup("myqueue", EventQueues.DESKTOP, true).subscribe(
new EventListener() {
public void onEvent(Event evt) {
if (evt.getName().equalsIgnoreCase("buttonClicked")) {
int thePreviousPage = (int) evt.getData();
.......

Related

How to access control from the popup fragment by ID

I want my text area to be empty after I press OK button.
I have try this line this.byId("id").setValue("")
onWorkInProgress: function (oEvent) {
if (!this._oOnWorkInProgressDialog) {
this._oOnWorkInProgressDialog = sap.ui.xmlfragment("WIPworklist", "com.sap.FinalAssestments.view.WorkInProgress", this);
//this.byId("WIP").value = "";
//this.byId("WIP").setValue();
this.getView().addDependent(this._oOnWorkInProgressDialog);
}
var bindingPath = oEvent.getSource().getBindingContext().getPath();
this._oOnWorkInProgressDialog.bindElement(bindingPath);
this._oOnWorkInProgressDialog.open();
},
//function when cancel button inside the fragments is triggered
onCancelApproval: function() {
this._oOnWorkInProgressDialog.close();
},
//function when approval button inside the fragments is triggered
onWIPApproval: function() {
this._oOnWorkInProgressDialog.close();
var message = this.getView().getModel("i18n").getResourceBundle().getText("wipSuccess");
MessageToast.show(message);
},
The text area will be in popup in the fragment. I am expecting the text area to be empty.
If you instantiate your fragment like this:
sap.ui.xmlfragment("WIPworklist", "com.sap.FinalAssestments.view.WorkInProgress", this);
You can access its controls like this:
Fragment.byId("WIPworklist", "WIP").setValue(""); // Fragment required from "sap/ui/core/Fragment"
Source: How to Access Elements from XML Fragment by ID
The better approach would be to use a view model. The model should have a property textAreaValue or something like that.
Then bind that property to your TextArea (<TextArea value="{view>/textAreaValue}" />). If you change the value using code (e.g. this.getView().getModel("view").setProperty("/textAreaValue", "")), it will automatically show the new value in your popup.
And it works both ways: if a user changes the text, it will be automatically updated in the view model, so you can access the new value using this.getView().getModel("view").getProperty("/textAreaValue");.
You almost have it, I think. Just put the
this.byId("WIP").setValue("") line after the if() block. Since you are adding the fragment as a dependent of your view, this.byId("WIP") will find the control with id "WIP" every time you open the WIP fragment and set its value to blank.
You are likely not achieving it now because A. it is not yet a dependent of your view and B. it is only getting fired on the first go-around.

How to get the gameobject- which triggered the UI.Button click function

in Unity 5- I am trying to disable a ui.button- once it is clicked. There is a list of buttons- among which- the clicked one will be disabled. But I am not sure, if it is possible to get the event triggering gameobject.
Unity Editor-
Code:
// called from ui.button clicks
public void callThisMethod(string param) {
// how to get the clicked button gameobject here
}
Just Add another event to return the button
public Button ButtonPressed(Button ThisButton)
{
return ThisButton;
}
You can add something like this to your code:
public Button yourButton;
public void yourButtonClicked(){
yourButton.interactable = false;
}
Assign your button to the Button object in inspector. Then where it says "On Click()" in the image you have above, select the script the above code is added to, and select the "yourButtonClicked()" function. That will disable the button once it is clicked.
To get your clicked button game object, you can use: EventSystem.current.currentSelectedGameObject
Pass the gameObject of the button as a parameter while your are adding event listener to the UI button.
Hope that helps:
GameObject myButtonGameObject = myButton.gameObject;
myButton.onClick.AddListener(() => {LogName(myButtonGameObject); });
public void LogName(GameObject buttonGameObject = null){
Debug.Log(myButtonGameObject);
}
Note: The given approach is useful, when you need to dynamically show the clicked buttons name, but if you know the exact button, you can make a public field for the myButton and get the name without passing any parameters.

Radio button change handler refreshing the page

I'm using UploadItem, RadioGroupItem and some other widgets. RadioButton is having onChangeHandler which will decide what all other components need to be displayed. I've uploaded some file using UploadItem. Then I changed the radio button selection. On changing the radio button, required widgets are getting displayed properly but whatever file I'd selected using UploadItem is going away. Fresh UploadItem widget is getting displayed. In other words page is getting refreshed.
My requirement is whenever I change radio button option, required widget should displayed along with that whatever file I had selected using UploadItem should remain same.
My Code is something like this:
UploadItem upload = new UploadItem();
RadioGroupItem radioGroup = new RadioGroupItem();
HashMap map = new HashMap();
map.put("option1","option1");
map.put("option2","option2");
radioGroup.setValueMap(map);
TextItem textbox = new TextItem();
radioGroup.addChangeHandler(new ChangeHandler(){
public void onChanged(ChangedEvent event) {
String radioValue =((String)event.getValue());
if(radioValue.equalsIgnoreCase("option2")){
textbox.show();
}else{
textbox.hide();
}
}
});
Add all created widgets to DynamicForm object using dynamicForm.setFields(all created widgets)
Changing the radio button should hide and show the textBox. But while doing that page is getting refreshed and whatever file we had selected using UploadItem is lost.
As per the documentation for hide() and show() of FormItem class, invocation of any of these methods, will cause the DynamicForm to be redrawn.
So it may cause the problem you're getting.
To overcome this issue, I would suggest you to put UploadItem in a separate DynamicForm.
fire an event on radio Selection change as
radioButton.addListener(Events.Change, new Listener<BaseEvent>() {
#Override
public void handleEvent(BaseEvent be) {
if(radioButton.getValue()){
//fire an event here for ur widget
}
}
});

GWT ListBox detect when value is re-selected

I'm having a problem using a GWT listbox. I have a case where the user selects a value from a listBox, but it can become invalidated if they change data in a related field. To validate the listBox, the user has to either select a new value, or confirm their old selection by selecting the same value again. I can't figure out how to determine if they have selected the same value so that I can restyle the listBox to look validated.
The valueChanged handler only detects if a new value is selected. The clickHandler and focusHandler fire too often because they fire when the user isn't selecting a value. Any ideas?
You can improve the clickHandler with something like this :
ignoreClick = true;
lastSelection = -1 ;
....
listBox.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
if (!ignoreClick) {
lastSelection = listBox.getSelectedIndex();
}
ignoreClick = !ignoreClick;
}
});
I tried it and the event was only fired if you selected an item. But you should rethink your user interface , like said above.

How can I tell a DefaultDataTable to refresh itself?

I am new to Wicket. I have a search page with two fields, startDate and endDate, inside a form that is inside a panel. The panel contains a DefaultDataTable. When the user submits the form, I use the startDate and endDate in the onSubmit() to get the results. However, my table remains empty. How do I tell the DefaultDataTable to refresh?
I have added a form and a submit button to this example. If I want to change the contents of the list, where do I do it?
Button submitButton = new Button("submitButton"){
#Override
public void onSubmit(){
System.out.println("submit button was clicked");
}
};
Form myForm = new Form("myForm");
myForm.add(submitButton);
add(myForm);
Ok, here is my comment as proper answer: make the DataProvider.iterator() dependend on the 2 Dates.