I am working on the project where i had used choice group in form. Now I want to get the selected item or index number of the choice group and want to perform some action.
I had tried through this:-
System.out.println(cgPrefs.getString(i) + (selected[i] ? ": selected" : ": not selected"));
But I am not getting the exact index number of the selected item in choice group.
You will get flags according to selection
boolean[] selectedFlag = new boolean[getChoiceGroup().size()];
using getSelectedFlags() method
getChoiceGroup().getSelectedFlags(selectedFlag);//getChoiceGroup() returns object of choicegroup
Now iterate and print
for(int i = 0 ; i < selectedFlag.length; i ++){
if(selectedFlag[i]){
System.out.println("Selected : "+getChoiceGroup().getString(i));
}else{
System.out.println("Not Selected : "+getChoiceGroup().getString(i));
}
}
Related
I am trying to use the toolbar search feature to search through a number of SwipeableContainers. Each container has a MultiButton on top and a number of buttons bottom left and bottom right. Essentially I receive data from a database and loop through the result adding a SwipeableContainer and set each one with a name (Line1 of the MultiButton) using sc.setName(). I then attempt to search using the code below:
Here is the code:
hi.getToolbar().addSearchCommand(e -> {
String text = (String)e.getSource();
if(text == null || text.length() == 0) {
// clear search
for(Component cmp : centercont) {
cmp.setHidden(false);
cmp.setVisible(true);
}
centercont.animateLayout(150);
} else {
text = text.toLowerCase();
for(Component cmp : centercont) {
SwipeableContainer sc = (SwipeableContainer)cmp;
String scName = sc.getName();
boolean show = text.length() == 0 || scName.toLowerCase().contains(text);
sc.setHidden(!show);
sc.setVisible(show);
}
centercont.animateLayout(150);
}
}, 4);
After I input the first character into the search I get this exception: java.lang.ClassCastException: com.codename1.ui.Label cannot be cast to com.codename1.ui.SwipeableContainer. If I press 'OK' past the error dialog, the search filters the options as expected for that 1 character. I get the same exception and result for the next character and so on.
I would appreciate some guidance on where I have gone wrong.
You have more than one component within centercont. One of them is a SwipeableContainer and the other is a Label.
You can workaround it by checking with instanceof before doing the cast but you might want to check your code/component inspector to see what's that label and if it should be there.
I am using the autocomplete textbox from this MSDN link.
Question:
CSWPFAutoCompleteTextBox has property "AutoSuggestionList" which I bound this to observable string collection. Each string is made of id + description. When user selects an item from dropdown, how can I override the texbox content? I want to manipulate the text box content.
This is a textbox that extends a wpf combobox to make it searchable.
When the user types in a string in the textbox, it displays matching strings as a dropdown, user selects an item and the item is displayed in the textbox.
the question is how to override the textbox contents of this control.
Without actual format of your code it is hard to answer precisely, but for example, if your strings are
string[] suggestions = {"0: Yes", "1: No", "666: whatever"}
Then you could get the number by something like
sugestedString.Substring(0, sugestedString.IndexOf(':'));
EDIT: I misunderstood the question. So if I now understands correctly, you might do it with
for(int i = 0; i < suggestions.Length; i++) {
if(suggestions[i] == selectedString) {
return i;
}
}
If you seek only a number within your list of all possible suggestions.
If you seek a number within narrowed-down suggestions, it gets somewhat more difficult.
You firstly need to note down what user has typed so-far (e.g. "Aut"). Then you need what he actually selected (e.g. "Automotive"). With those things, you can then search all your possible suggestions, count how many of them satisfies the user-typed beginning and finaly which of them is the selected one. It might look like this:
int counter=0;
for(int i = 0; i < suggestions.Length; i++) {
if( suggestions[i].StartsWith(typedString)) {
counter++;
if(suggestions[i] == selectedString) {
counter;
}
}
}
I need to add multiple values (ID fields of another custom list) to a Multiple Lookup field using Sp-services.
What is the correct format of the data to be used ?
I have tried like ( 5,9,6 ) but only selecting the first item.
I am not quite sure why do you want to do this, because these items you will add - they can't be saved as values, because there is a relationship between the column and lookup list, i.e. if you have Lookup column to the List1 and you add a new value from the List2 with id 99 and save, it will save the reference to the list item with id 99 in the List1.
but if anything, it is possible, this is how I am appending multiple lookup selected values:
var lines = additionalTechnologies.split(';#');
$.each(lines, function (index) {
if (lines[index].length < 3) {
$("select[title='Additional Technologies selected values']:first").append("<option value=" + lines[index] + " title=" + lines[index + 1] + ">" + lines[index + 1] + "</option>");
$("select[title='Additional Technologies possible values'] option[value=" + lines[index] + "]").remove();
}
});
and remove them from the all items list. just do it vice versa.
I have found a way to do it.
// "list1Id" contains the array of LIST1 ID fields that you want to add...
// "MULTIPLELOOKUPFIELD" is the multiple lookup field in the LIST2...
var multipleLookupValue ="";
for(i = 0; i < list1Id.length ; i++)
{
multipleLookupValue = multipleLookupValue + list1Id[i]+";#data;#";
}
var method = "UpdateListItems";
$().SPServices({
operation: method,
async: false,
batchCmd: "New",
listName: "LIST2" ,
valuepairs: [["MULTIPLELOOKUPFIELD",multipleLookupValue]],
completefunc: function (xData, Status) {
//alert("Added new item to LIST2 list");
}
});
May be it will help someone...
I'm trying to get a field to update with each line item on the invoice (without over writing what is already there), using a Query Expression to get the data that needs to be used to update the field.
So far I've been able to get this to work just fine when only 1 line item is present. But whenever I test this against multiple line items I get the " The given key was not present in the dictionary." error.
Any help or nudge in the right direction?
QueryExpression lineitem = new QueryExpression("invoicedetail");
lineitem.ColumnSet = new ColumnSet("quantity", "productid", "description");
lineitem.Criteria.AddCondition("invoiceid", ConditionOperator.Equal, invoiceid);
EntityCollection results = server.RetrieveMultiple(lineitem);
Invoice.Attributes["aspb_bookmarksandk12educational"] = "Purchases";
Invoice.Attributes["aspb_bookmarksandk12educational"] += "\n";
Invoice.Attributes["aspb_bookmarksandk12educational"] += "Product" + " " + "Quantity";
Invoice.Attributes["aspb_bookmarksandk12educational"] += "\n";
foreach (var a in results.Entities)
{
string name = a.Attributes["description"].ToString();
string quantity = a.Attributes["quantity"].ToString();
Invoice.Attributes["aspb_bookmarksandk12educational"] += " " + name + " ";
Invoice.Attributes["aspb_bookmarksandk12educational"] += quantity;
Invoice.Attributes["aspb_bookmarksandk12educational"] += "\n";
}
"The given key was not present in the dictionary."
Suggests the problem lies in the way you are trying to access attribute values and not with the multiple entities returned. When you try get an attribute value, try to check if the attribute exists before reading the value like so:
if (a.Attributes.ContainsKey("description"))
{
var name = a.Attributes["description"] as string;
}
Or even better use the SDK extension methods to help do the check and return a default value for you like so:
var name = a.GetAttributeValue<string>("description");
var quantity = a.GetAttributeValue<decimal>("quantity");
My Xpage has a dataView that points to a view which is sorted by employee name. One of the other fields in the employee view is their Location. I have a combobox in the header of the view that allows a user to subset to one location. When subsetted the correct employees appear, but the sort order is lost.
I have looked at a few answers in Stack overflow such as this and this. but cannot get them to work. I think the difference is that
I am not trying to filter on a value that is sorted.
Here is my code for the FT Search:
var tmpArray = new Array("");
var cTerms = 0;
//Geo Location Search
if(viewScope.key != null & viewScope.key != "" & viewScope.key != "All Locations" & viewScope.key != "--Select a Location--") {
tmpArray[cTerms++] = "(FIELD HR_GeoLocation = " + viewScope.key + ")";}
qstring = tmpArray.join(" AND ").trim();
viewScope.queryString = qstring; // this just displays the query
return qstring // this is what sets the search property
The view's first field is the users last name, first name, descending.
FTSearch doesn't return found documents in view's order:
The collection of documents that match the full-text query are sorted
by relevance, with highest relevance first.
Use an additional view which is categorized by Location and use Location as key in
Filter by category name (categoryFilter) or
Filter by column value
(keys/keysExactMatch)
The columns after Location-column are the same as in your current view.