Getting multiple drop down dynamically in JSF - jsf

I have a hierarchy of parent child relationship in database and based on those values, I need to add new values. The hierarchy could be different and the drop down needs to be displayed dynamically. E.g. Lets say we have 2 hierarchies: NorthAmerica>USA>California and NorthAmerica>USA>GWA>Seattle. So when I try to add a new Location, if I select NA at first level, USA at second level and California at third level, then the last drop down should be of the locations which are children of California. In other case, if I select NA at first level, USA at second level, GWA at third level, then fourth drop down should show of Seattle and the last drop down should be of the locations which are children of Seattle.
The number of drop downs are shown based on the values present in the database. I doubt that it can be done using ui:repeat but I am not getting the right direction. It would be great if someone could help with any positive pointers.

If you are able to make Map<K,V> map
Where K=String(Id for value) and V= List<SomeObjectClass>
SomeObjectClass=> String id, String Value.
Now Map will looks like Key
Key Value
1 1.1,1.2
2 2.1,2.2
1.1 1.1.1,1.1.2
1.2 1.2.1,1.2.2
2.1 2.1.1,2.1.2
2.2 2.2.1,2.2.2
So if I use key 1.1 I will get list of 1.1.1, 1.1.2
One more List<ID> this will holds your selected value from drop down. And size will tell you how many drop down need to display.
Put “0” at index 0 in list, list should not be empty. Now loop over List and show number of drop down as size of list.
Dropdown value will be come from map.get(K).
UI:repeat over List<ID> var=varlistId (You know how)
Dropdown: value=#{map.get(VarID)} iteamlevel=” somevariable.level” ItemValue=”somevariable.id” var=”somevariable” DropDown END
UI:repeat END
You need to add selected Id From dropdown to list, and remove if user make any change in previous drop down, and remove all element from List.
Example:
At Page load, you list size will be 1 you have add 0 at 0 index of list, now your UI will show one drop down with map vale where you have two element 1,2;
If you select 1 or 2 from drop down, add this in list at index 1 as add method will add at last.
Now you have to drop down in UI repeat, first drop down will how 1,2 and second drop down will show 2.1,2.2,
Now if you have ten drop down and user change value in 5th drop down, now you need to loop over list and need to remove element from 6th so you list have 6 value and you UI will show only 6 drop down.
Give your suggestion below
Edited:
We can replace the map by some method which will give the next value for drop down. As suggest by #Kukeltje.

Related

How can I randomly select items into multiple lists, with each list being unique?

Say I have 5 groups with 10 spaces for people in each. I want to randomly select and place people from a list of 100 until the groups are filled.
I understand how to do this with one list (ie randomly finding 10 names from the list), but I'm unsure how to do this given that people can't be in multiple groups. I need to somehow be randomly selecting the people for the second group from a pool of the 100 - the people selected in the first group, etc.
Any thoughts about how to go about doing this?
With your list in column A:
=INDEX($A:$A,AGGREGATE(15,7,ROW($A$1:$A$100)/((COUNTIF(C$1:C1,$A$1:$A$100)=0)*(COUNTIF($B$2:B$11,$A$1:$A$100)=0)),RANDBETWEEN(1,COUNTA($A$1:$A$100)-COUNTA(C$1:C1)-COUNTA($B$2:B$11)+1)))
Notes:
C$1:C1 needs to refer to the cell above the left top cell in which the formula is placed
$B$2:B$11 needs to point to the cells to the left of the groups and they must be empty
$A$1:$A$100 is your data set of names(I used 1 to 100)

Matching Column B with A, and then sorting B with its expanded selection

I have to sets of data.
The first set is just a bunch of IDs.
The second set is the same set of IDs and other data related to each ID.
But the second set of IDs is not in the same order as the first set.
So how do I get the second set to match up in the same order as the first set and also sort the items related to it?
So, here is an unsorted example:
I need to get from that to the following:
Anyone know the simplest way to do this, keeping in mind that the 2nd set has to be sorted along with its relations?
JH
First of all, I don't know if you have any duplicate IDs in the first or second, but we'll cover them anyways.
First, create an enumeration to hold the sort order of what you have in the first table.
=IF(ROW(A2)=2,1,IF(B2=B1,A1,A1+1))
This basically just keeps the order that you have. If it's the first row you're using, give it a 1. If the ID on the current row is the same as the previous (a3 = alpha, a2 = alpha), keep whatever the previous ID was (so that duplicates are enumerated identically). Otherwise, increment the ID.
Then, on your other table, bring over the ID you created with a lookup formula - index match, vlookup both work.
=INDEX($A$2:$A$5, MATCH(E2, $B$2:$B$5, 0))
Finally, just sort the new lookup column on the second table.
Alternatively, you can cut out the first step of enumerating them and just use MATCH on your table 2 IDs to table 1 IDs and it will return the row position that it is in.
=MATCH(id in second table, <array of IDs in first table>, 0)
You can then sort based on that. It may or may not be more intuitive to do it one way or the other.

SharePoint Calculated Field resets on item edit

I am using a SharePoint list that was migrated from an old Windows 2003 server to an existing 2008 server. This list is used to track issues raised by users against another application - a list of jobs to do if you will.
In the old list there was an Id field. When the list was recreated in the new area the assigned ID number was different, for example
Old ID New ID
--------- ---------
5 204
6 2
7 3
8 159
9 4
This assignment does appear to be fairly random.
To negate this a calculated column was created, so IDs raised before the migration use the Old ID number, and new calls raised after the migration use a calculated value. The calculation is
=IF(ISBLANK([ID (Old)]),ID+8,IF([ID (Old)]<=348,[ID (Old)],ID+8))
This compares the ID (Old) to blank, and if so, it is a new call and should have the default ID number, plus 8 (I think there was a total of 8 calls made during development that were then removed).
Otherwise if the Old ID number is less than 348 (the call number when we migrated), use the Old ID number.
If neither condition is met, simply set the ID to the new ID number plus 8.
This works fine when creating new calls.
The problem arises when I edit a call. For example if I set the ETA to a new value and save the call, the Calculated ID is always reset to 8.
I can fix this by going in to List Settings -> Opening the calculated column -> and clicking OK. This reapplies the calculation and everything is numbered correctly again.
For information - due to the environment this is deployed in I am not able to use SharePoint Designer at all.
The question is, how can I stop the renumbering when I edit an item?
The ID field behaves a bit oddly with calculated columns. A calculated column formula will find the ID of an item and resolve it properly when items are created or when the formula is modified, but as you discovered, when an item is modified, the formula can't find the ID value. (My guess is that this has to do with the ID field not being included in the list of column values being sent to the database on update, perhaps because the ID field should never change.)
One way around this is to use a workflow (or a custom event handler, if you have too much time on your hands) to copy the ID field to another column, such as a number or single line of text column, whenever an item is created. You can then use that new column in your formula instead of using the ID column.
To prevent people from updating your dummy ID column, you can hide it from the forms. To do this, first enable management of content types for the list, then edit the Item content type, find the new dummy ID column, and change it to "Hidden" (instead of "Required" or "Optional").

How to modify Choice field values (add & remove) without altering the original entries

I am working with a SharePoint list that has a "Category" column, which is a choice field, let's just say the categories are A,B,C,D (right now) for simplicity. At the beginning of the fiscal year (1.5 months) these will not be the same- some additions and deletions will be needed, but we need to make sure the original list values for this field do not change (the ones that have already been entered).
If I modify the Choice field values directly to remove an item, let's say A, will it remove all instances of A throughout the list? ie. Am I safe to edit this field directly, or should I create a "Historical Category" column to store the old values.
Just set up a test list with a choice column containing values 1,2,3,4. Created a few list entries, then modified the choice column values to 11,12,13,14. Original list entry values for the choice column did not change (ie they were preserved). My conclusion is that it seems like modifying the choice column values will not alter the original list entries, although you must be careful to not overwrite them with one of the newly modified values.

SPD: calculated column with data from another list

I'm in the same situation described HERE.
I'm trying to use Create List Item and Update List Item actions (like suggested in the answer) but without any results.
Could someone kindly explain the procedure mentioned in the answer?
Thank you,
Marcello
I posted an answer there, but here is a copy in case it gets deleted or removed:
lem.mallari's answer is a huge pain unless you can assume that the Amounts in List A never change, since it's not tracking whether an item has already been added to the sum. There is no way for a Workflow to iterate through a SharePoint list, which means there is no easy way to calculate the sum or average of multiple list items.
The correct way to implement this will will require some development. The SharePoint Developer Training (2010, 2013) will actually get you most of the way there: an event receiver should trigger when items are added or changed in Lists A and B that uses SharePoint's API to go through List A and average values by Name, then update all (or just affected) items in List B. Alternatively, you can use JavaScript to display the sum of all entries in List A that have the same name as the item in List B as long as all the data is displayed on your page. If you're handy with XPath and InfoPath, you could add List A as a secondary data source to List B's form and select only applicable items in List A to sum from.
But if we're talking Workflows, here's the "workflow only" method. This was tested and successful in 2010. Create custom List C with the following columns:
Title (string, mandatory, enforce unique values)
TotalItems (integer, mandatory, default 0)
Sum (number, decimal places however you want, mandatory, default 0)
Average (calculated, =IF(TotalItems=0,0,Sum/TotalItems)) (optional)
Replace the Name columns in Lists A and B with lookup columns pointing at List C. Delete the Amount column in List B, instead including the Sum column as an additional column. Add the following columns to List A, and ensure that users cannot change them directly. This can be restricted by making InfoPath forms or by making alternative view and edit forms.
AmountArchive (number, identical to Amount, default 0)
AmountHasBeenSubmitted (yes/no, default no)
Create a Workflow to run each time an item is created or modified in List A. Use these commands (I'm using a list for readability; it was getting ugly when formatted as code):
If Current Item:Amount not equals Current Item:AmountArchive
Set Variable:Item Count to (Data source: List C; Field from source: TotalItems; Find the List Item: Field Title; Value: Current Item:Name(Return field as: Lookup Value (as Text)))
Calculate Variable:ItemCount plus 1 (Output to Variable: ItemCount)
Calculate List C:Sum (similar settings as above; be sure to use Lookup Value (as Text) and not String!) minus Current Item:AmountArchive (Output to Variable: SumWithoutValue)
Calculate Variable: SumWithoutValue plus Current Item:Amount (Output to Variable: NewSum)
If Current Item:AmountHasBeenSubmitted equals No
Set AmountHasBeenSubmitted to Yes
Update item in List C (Set TotalItems to Variable:ItemCount; Set Sum to Variable:NewSum; Find the List Item in the same way of Field:Title; Value: Current Item:Name(Return field as: Lookup Value (as Text))
Else
Update item in List C (don't do anything to TotalItems; use the same logic to set Sum to Variable:NewSum)
Set Amount to Current Item:AmountArchive

Resources