I am using GWT combobox with Select item (dropdown checkbox)
I want to make some items defaultly checked, but i cant find any solutions..
#Override
protected void success(List<warehouseDTO> t)
{
warehouse_list = t;
for (int i = 0; i < warehouse_list.size(); i++)
{
whl.put(warehouse_list.get(i).getId() + "", warehouse_list.get(i).getName());
}
selectItemMultiplePickList.setValueMap(whl);
selectComboForm.setItems(selectItemMultiplePickList);
}
On new "Article" (thing in warehouse) its good, but on edit i need to have checked by default.
Maybe its posible with setAttribute but cant find list of attributes.
Thanks
You should use the following:
setValues(values);
Here values accepts multiple String values.
Now as you're doing:
whl.put(warehouse_list.get(i).getId() + "", warehouse_list.get(i).getName());
your key for the combobox will be warehouse_list.get(i).getId() and value will be warehouse_list.get(i).getName().
So to show multiple values as selected values, you need to pass multiple warehouse_list.get(i).getId() as values.
For example, if you want show first 3 values as selected, you can do the following:
selectItemMultiplePickList.setValues(
warehouse_list.get(0).getId(),
warehouse_list.get(1).getId(),
warehouse_list.get(2).getId());
Related
I have a comboBox in XPages which is showing an hierarcal list of categories and values populates as a vector in SSJS.
I now want to apply a styleheet (bold) to the categories (i.e on only the categories of the generated option tags)
please note that I do not need a lesson in how stylesheets work. I need to know how to add a class or style to the categories in the outputted options tags
how can I do that?
thanks
Thomas
UPDATED MY QUESTION WITH A WORKING CLASS
Mimics a categorized view with 3 columns in a comboBox, category, label and value
public class Utils {
public static List<SelectItem> getGroupedComboboxOptions() {
try {
Database db = ExtLibUtil.getCurrentDatabase();
View vv = db.getView("ProdukterByCat");
Vector v = vv.getColumnValues(0);
List<SelectItem> groupedOptions = new ArrayList<SelectItem>();
SelectItemGroup group;
for (int i = 0; i < v.size(); i++) {
List<SelectItem> options = new ArrayList<SelectItem>();
group = new SelectItemGroup(v.get(i).toString());
ViewEntryCollection nvec = vv.getAllEntriesByKey(v.get(i), true);
ViewEntry entry = nvec.getFirstEntry();
while (entry != null) {
SelectItem option = new SelectItem(entry.getColumnValues().get(2).toString(),entry.getColumnValues().get(1).toString());
options.add(option);
entry = nvec.getNextEntry(entry);
}
group.setSelectItems(options.toArray(new SelectItem[options.size()]));
groupedOptions.add(group);
}
return groupedOptions;
} catch (NotesException e) {
e.printStackTrace();
}
return null;
}
}
A combobox in XPages is rendered using a HTML select tag. If you organise the options in optgroup's (see also Populating selectItems of the combobox (label, value) using a managed bean) you get some default styling out of the box. Example here.
You can even apply additional styling on them with standard CSS by targeting the optgroup. But support for that is limited: it doesn't work on an iPad for example.
If you want more control on how your dropdowns look, I'd suggest to use a plugin like Select2.
I am using Wicket to generate a form to allow users to set values for several model objects. Each model object has two fields, operNam and slaNam. The list of operNam values is taken from a parameter string operationNames and I split this space-separated list as shown below and put each one into an ArrayList called myListResult.
String result = parameters.getString("operationNames");
//split list
ArrayList<String> myListResult = new ArrayList<String>(Arrays.asList(result.split(" ")));
for (String word : myListResult) {
System.out.println("===>" + word);
}
What I want to do, is create a form for the user with two elements for each entry in myListResult. I am adding a TextField containing the value of each operation name in myListResult and an empty TextField to allow the user to enter values for slaNam. The code I'm currently using to do this is below:
for(String operation : myListResult) {
form.add(new TextField<String>("operNam" , new PropertyModel<String>(operation, "operNam")));
form.add(slaNam);
}
add(form);
The problem I have is that the above code is adding TextFields with an id value of operNam for each item in myListResult and this is throwing an error due to duplicate id elements in the html. I also tried doing it as follows:
for(String operation : myListResult) {
form.add(new TextField<String>(operation , new PropertyModel<String>(operation, "operNam")));
form.add(slaNam);
}
add(form);
This avoids the problem of duplicate id elements but causes a problem because now my form elements don't map to my model object which expects a field called operNam and another called slaNam.
My Question is
How would I create form elements that represent an arbitrary number of models without using duplicate element id names.
Heres a image of how I would want the html to look if I had 4 items in myListResult:
You should use a Repeater to add your TextFields. For example a ListView
ListView listview = new ListView("listview", list) {
protected void populateItem(ListItem item) {
item.add(new TextField("textField", item.getModel()));
}
};
With approriate HTML:
<span wicket:id="listview">
<input wicket:id="textField" type="text"></input><br/>
</span>
To use multiple fields in each row, the easiest solution is to use objects that contain these fields:
public class MyRow
{
public String slaNam;
public String operName;
}
And create a List of them:
List<MyRow> myRows = new ArrayList<>();
And use this list in the ListView
ListView<MyRow> listview = new ListView("listview", myRows)
You can use this in the populateItem
protected void populateItem(ListItem<MyRow> item) {
item.add(new TextField("slaNam", new ProperyModel(item, "slaNam")));
item.add(new TextField("operName", new ProperyModel(item, "operNam")));
}
Or, use a ProperyListView for even less code :)
I have requirement to sort group summary field.
Ex. I have 3 columns in the grid.
Step 1 : I have group by Id by dragging the Id column in Group by area.
Step 2: Add Sum,Count,Average on column.
Now i want to sort sum or count or average by clicking on that ,so that the whole grouped is sorted by sum like 100,200,300.
please help
The sort order is controlled by the GroupByComparer of the FieldSettings class and this can be accomplished by creating a custom IComparer for the field that is grouped. Note that grouping is actually also a sort so I am going to assume that you still want the default sort to happen when the column is first grouped.
In the following example group by records can be sorted by a single summary result when it is clicked on. This was accomplished by using a custom IComparer for the groups that sorts by the value of the tag if it is set and if not set falls back to the value of the group by record:
public class SummarySortComparer : IComparer
{
public int Compare(object x, object y)
{
GroupByRecord xRecord = x as GroupByRecord;
GroupByRecord yRecord = y as GroupByRecord;
IComparable xValue = xRecord.Value as IComparable;
object yValue = yRecord.Value;
if (xRecord.Tag != null)
{
xValue = xRecord.Tag as IComparable;
yValue = yRecord.Tag;
}
return xValue.CompareTo(yValue);
}
}
This is set on the grid using the following:
this.XamDataGrid1.FieldSettings.GroupByComparer = new SummarySortComparer();
Use the PreviewMouseLeftButtonDown of the grid to get the summary that was clicked on if there was one and set the tag of the group by records to be the value of that summary and refresh the sort of the grid:
void XamDataGrid1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
SummaryResultPresenter summaryResultPresenter =
Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof (SummaryResultPresenter), false) as
SummaryResultPresenter;
if (summaryResultPresenter != null)
{
GroupBySummariesPresenter groupBySummariesPresenter =
Utilities.GetAncestorFromType(summaryResultPresenter,
typeof(GroupBySummariesPresenter), false) as GroupBySummariesPresenter;
if (groupBySummariesPresenter != null)
{
SummaryResult summaryResult = summaryResultPresenter.SummaryResult;
int summaryResultIndex = summaryResult.ParentCollection.IndexOf(summaryResult);
foreach (GroupByRecord groupRecord in groupBySummariesPresenter.GroupByRecord.ParentCollection)
{
groupRecord.Tag = groupRecord.ChildRecords.SummaryResults[summaryResultIndex].Value;
}
this.XamDataGrid1.Records.RefreshSort();
}
}
}
Note that there are a few limitations in this example in that I haven't implemented any way to clear what summary is sorted so that is something that if desired would still need to be implemented by you. I also didn't include logic to change the sort direction and used the direction that the field is currently sorted by so if you also want to update the direction this will need to be added as well.
I have 10 comboBox in a groupBox
for I just want to display a calculated value in respective comboBox like this say if I set a varible double i=08.00; then on button click cmboBox should display values like this
CB1-08.00
CB2-09.50
CB3-10.00
CB4-10.50
CB5-11.00
CB6-11.50
.... and so on upto CB10 But I am getting output like this
And Code
private void button1_Click(object sender, EventArgs e)
{
double i=08.00;
foreach (var comboBox in groupBox1.Controls.OfType<ComboBox>())
{
comboBox.Text = i.ToString("00.00");
i = i + 0.5;
}
}
Your combobox order is different in the collection so it inserts the numbers randomly. May be you can name your combobox for instance like cmb1,cmb2,cmb3 etc. and if you update your code it will run.
Your controls in the Controls collection are not sorted by their appearance on the form. You will need to find a way to sort them if you need different values in each based on their position.
Foreach loop doesn't give the collection in the order you wanted. The way to go forward is to give a tag id to each combo box, then you can use that to assign a value to them them.
So your first combo box will start with tag id 0, and the last one will have 8,
double val = 08.00;
for (int i = 0; i < groupBox1.Controls.Count; ++i)
{
var combobox = groupBox1.Controls[i] as ComboBox;
int tag = int.Parse(combobox.Tag.ToString());
double value = val + (0.5 * tag);
combobox.Text = value.ToString("00.00");
}
Make sure you tag the cobbo box in the order you wanted them.
I am trying to find the index of a particular value from the CheckedListBoxControl. The CheckedListBoxControl has a DataSource, DisplayMember, ValueMember set to a DataTable and two columns receptively. Now I have to set the CheckedState Property to true by finding its index from CheckedListBoxControl by using some value from the ValueMember and then calling the SetItemChecked() method with that index.
I'm not able to find any property or method which returns the index. Please help.
If a list box control is bound to a data source, you can iterate throught all listbox items using the the GetItem() method and the ItemCount property:
for(int i = 0; i < checkedListBoxControl.ItemCount; i++) {
object dataRow = checkedListBoxControl.GetItem(i);
}
To find the index of the specified item you can use the FindItem() method
searching by DisplayText:
string s = "searchString";
int index = checkedListBoxControl.FindItem(startIndex, true, delegate(ListBoxFindItemArgs e) {
e.IsFound = s.Equals(e.DisplayText);
});
searching by ValueMember:
object value = 100;
int index = checkedListBoxControl.FindItem(startIndex, true, delegate(ListBoxFindItemArgs e) {
e.IsFound = object.Equals(value, e.ItemValue);
});
Please also take a look at the "How to get checked rows of a data-bound CheckedListBoxControl" article.