onclick event of button requires double click - xpages

I have a viewPanel using DB2 for the datasource. I have created a comboBox containing all the possible viewPanel columns, a radioGroup to select ASC or DESC, a comboBox containing all the possible viewPanel columns with an onchange event to partially update the values in another comboBox, and a final comboBox that has all the values from DB2 according to the previous comboBox value that has an onchange event to partially update the viewPanel.
The onclick event for my button has this code and does a partial update of the viewPanel:
var sort:String = getComponent('comboBox1').getValue();
var order:String = getComponent('radioGroup1').getValue();
var vp = getComponent('panel_container').getData()[0];
vp.setDefaultOrderBy(sort + " " + order)
The problem is that I have to click the button twice to get the code to actually run. The first click is ensuring the onchange event is fired, then the second click activates the code. I have tried to use Full Update and checking the 'Set partial execution mode' with the partial update.
How do I get the onclick event for my button to work on the first click?

Too much event tango :-) Here is what I would do:
bind your combo boxes to viewScope variables. That's more robust than getValue() and allows to change the UI later (fancy some d&d)
use the combo box client side, not the server side onChange() event. This would require all values to be send down eg via Ajax
when you click the button make sure the fields are inside the panel you refresh
Hope that helps

Related

Xpages repeat value depends on a value outside of the repeat

Hardly I managed to build a repeat with 2 inputText that do some math depending on the value of another inputText(let's call it outside_input) which is outside the repeat.
Everything is working fine, but the problem is when I want to change the value of the outside_input the values of the inputTexts inside the repeat doens't automatically refresh. I have a partial refresh on the repeat.
The 2 fields inside the Repeat are binded with a viewScope. And the script is on the first field on the onChange method.
Is there a way that when I change the outside_input I could trigger the onChange method of the inner fields?
Put the partial refresh on the first field (that has the onChange event) and specify to refresh the repeat or a panel that contains the repeat and whatever other fields rely on it. Note that this requires your onChange event to be server side code not client side code.
Howard

How to access specific buttons on a collection view tin 4 buttons and 1 image view

I am currently populating a collection view with images but at the same time have some button option.
How can I know which button I press if let's say it populated about 4 of those cells?
How do I make a code to handle that event?
Add actions to each button in your collectionView cell. Or add one action to all of them and set tag for each button. Then in action method
UIButton *btn = (UIButton *)sender;
//btn.superview will be your button parent view (cell for example)

Action Button works differently if added to the DataView

I have a button that calls a Dialog that has a combo box bound to a sessionScope variable. The combo box contains a list of form names that I use to then call an XPage to create a new document. The first value in the forms list is "" so the user needs to select a value. I have a button with the onClick event of:
var c = getComponent("CreateDocDialog");
sessionScope.put("ssSelectedForm","")
c.show();
I have the button and dialog on a customControl with a repeatControl and when the button to open the dialog is clicked the ssSelectedForm is null and the current value of the combo is blank, which is exactly what I want it to be. However, if I add the same button and dialog to a customControl with a dataView control the dialog displays but ssSelectedForm is not null so the combo box displays the last value of ssSelected. I have placed the button outside the dataView, in several of the facets on the dataview, but all with the same results.
Very confusing.
Bill,
I am going to answer the same as my comment since I am pretty confident about what I said.
Go ahead and change the scope from sessionScope to viewScope. I had a similar issue once, and I 'fixed' it by clearing out the sessionScope variable after I used it. This worked, but I realized that it was not necessary, and that by changing to viewScope the lifecycle will be shorter and there was no need to clear out the value when I was done with it.
I don't know why this fails when added to the data view, but if this fixes it that would be all that matters.

Trick ComboBox into thinking its' dropdown is open when it's not

I found a control that displays a CheckedListBox for the dropdown of a combobox. I like this but I want to improve upon it. I want to perfectly replicate the behavior of the standard combobox like so:
When the user clicks the combobox the dropdown (CheckedListBox) opens.
When the user clicks inside the dropdown they have no problem checking multiple options.
When the user clicks the ComboBox again the DropDown hides.
When the user clicks off the combobox (ANYWHERE, be it on a control or just the form), the DropDown gets hidden.
I found on P/Invoke.net the PostMessage function in the User32.DLL library that allows you to send a message to the ComboBox using the CB_SHOWDROPDOWN (0x014F) message to force it to immediately close the native DropDown.
The problem in doing so is that it will automatically force call the OnDropDownClosed function of the base ComboBox control. This I would not care about but it stops the natural feeling of the control (for me at least) in that if you do some trickery with it to keep your custom dropdown open, it still stays open when you click off the control (because the ComboBox thinks it's dropdown is closed already).
That is the behavior I want to avoid. I want the ComboBox to think that it's DropDown is still open when it's not (until the user either clicks the combobox to close it or clicks off the control).
Also, the problem I was experiencing before just letting it open the native combobox dropdown was that when I went to click on the custom dropdown, the ComboBox fires the OnDropDownClosed function and (seeing as how I override that method to hide the custom dropdown), my dropdown is hidden.
So...
How do I override the OnDropDown method to open up a custom custom dropdown that, when clicked, will not fire the OnDropDownClosed method, I guess, is the short way of asking the question.

Computing checkbox choices dependent on radio button selection

I want to be able to select a value in a radio button in XPages, then use that value to determine the choices in a set of checkboxes.
The choices for the radio button are found using a DbLookup to one view. There is some javascript that puts the text value of the radio button lookup into a hidden field. Based on that value, the checkbox choices are determined with another DbLookup.
I keep fiddling with the code and can never get it to use the updated value of the hidden field to recompute the choices for the checkboxes, even if I display it.
<xp:selectItems>
<xp:this.value>
<![CDATA[#{javascript: var viewName=reportDoc.getItemValueString("viewChoice");
var tmp = #DbLookup(#DbName(),"dbprofile",viewName,"Value");
#If(#IsError(tmp),"None",tmp)
}]]></xp:this.value>
</xp:selectItems>
I'm sure this is actually pretty simple, but I just can't figure it.
You need to set the onChange event of the radio button to partially refresh the checkBox control. This ensures that the values of the checkBox control are refreshed.
The checkBox control can read the value of the radio button control using getComponent("id of radio button control").getValue() and use this value instead of the hidden field for the DbLookup.

Resources