How to select all elements of the same kind in RichFaces - java

As far as I know, there are several functions in RichFaces that allow to get a reference to a "rich:" component by its id from javascript. But in my case I can have arbitrary amount of collapsiblePanels and need a way to expand them all upon a button click. Is there a solution?

Richfaces does not offer such a function. You can try to use JQuery to query for the class .rf-cp that is common to the CollapsiblePanel and try to get it from there.
Of course, since all of the "arbitrary number" of panels will come from your code, I think that maybe it would be safer to, each time a new panel is created by your .xml, you add its id somewhere (Javascript code, hidden field, etc.) and use it from there.
The list of richfaces available functions: http://docs.jboss.org/richfaces/latest_4_2_X/Component_Reference/en-US/html_single/#chap-Component_Reference-Functions

Related

how to move items from available section of palette to selected section based on the item selected in the dropdown of same form?

In Wicket, I have created a form containing one drop down and palette of same data type. If I want to move items from available section to selected based on the value selected in the drop down. How to do that?
2 ways to do this: either client-side with javascript or server side with ajax.
If you were to do it with Ajax, you could use an AjaxEventBehavior to detect that there was a change in the dropdown. Then change the model of the palette's selection to whichever items you'd like to be selected. Then re-render the palette by adding it to the AjaxRequestTarget given to you by the AjaxEventBehavior#onEvent. This would have a slight latency compared to the javascript solution, but it would be cleaner, as it would use Palette the way it was meant to be used (in a sense). I feel like it could make your life easier down the line.
If you were to do this via javascript, you could bind an onchange event listener to your dropdown, which would move the options from one side to another. The palette works by using two <select> components for the display and a single <input type="hidden"/> for passing the selection back to wicket. In order to do what you ask via javascript you would have to move the <option> components from one <select> representing unselected components to the other, and then modifying the value of the hidden input to contain/no longer contain the ID value of the selection.
This solution is a bit more dirty in my opinion, but it would probably reap you the best performance.

Wicket: AutoCompleteTextField with "favourites"

I need to build an AutoCompleteTextField-like component where the user can mark some options as favourites (when he starts to write, some options show up and each option has a checkbox to mark it as favourite). The user can then check a checkbox outside the AutoCompleteTextField to choose whether only the favourites will be shown or on the contrary all the values no matter if they are favourites or not, will be all shown.
I have read Using panels instead of String in Autocompletetextfield and i think it could be done using IAutoCompleteRenderer...
Any ideas?
I would go with the solution provided by Robert in https://stackoverflow.com/a/15484348/461499.
Why?
If you have complete control over how the choices are rendered (by using plain Wicket Components instead of javscript), you can built a very rich component. Although I think it will take some extra javascript effort to make the choices-panel look and feel correct, it should be worth the investment.

Best way to implement a selection box from a large number of entries

I have a large set of data from which the user has to select one. I'm thinking of a way to implement it (of course, in a GUI). I have a few ideas. But just thought of posting here as there may be better alternatives..
Say, user has to select a name from a large set of user base. If I simply put a text field for user to enter the name, then there can be issues like entering same name in different formats, misspelling etc...
I see two options here
Using a combo box
Using a list (Actually i'm thinking of something like a tool tip. As I cant show the whole list always due to space issues)
But combo box won't be much user friendly i guess. As the user will have to scroll around the whole list to select an entry. If the number of entries are too large, this will be
Which means, now I'm left only one option. A popping up list, which will change the content according the text user is entering in the text field. So he can type first few letters and the list will show all the entries starting from the entered text. Got my point, right?
Are there any other better to achieve this kind of need?
If I'm going to implement above, what will be the best way to follow. I'm thinking of extending the JTextField to add required functionality. Well, I'll put some method to set the popup list entries. And I'll add some actionListner to watch the text field, and control the popup list accordingly...
Autocomplete is what you are probably looking for. Google for "java swing jcombobox autocomplete" and limit results for the last couple of years to get relevant results. There will be a lot of examples and ideas on how to implement this with custom code.
I believe there is also some custom libraries like "swingx" that provide at least partial or full implementations to save time.
http://swingx.java.net/
They have released code as recently as the beginning of this years so it appears active and might have what you need.
You could take a look at SwingLab's autocomplete feature, it allows you to attach it to a JCombBox, JList or JTextComponent
use AutoComplete JComboBox/JTextField
based on Standard Java Classes
no issue with larger sets of data
no issue with Focus, BackSpace Key, Caret
for better performance to required sort the array before use
simple workaround for setStrict(true/false), restrict input to array

JSF List of Values Options

I am using JSF 1.1 and I'm looking for a JSF list of values component.
I have a button and when I click that a popup window should open with one text field and buttons, where either I could search for what I am looking for in the text field or select all the values when I click on the buttons and from the available list of values I should be able to select one item.
Is any such type of component available in JSF 1.1 or with the icefaces, richfaces or apache jsf components?
Your question title is a little bit confusing, as you don't seem to ask for just a "list of values"-component, but a bunch of different components. Your situation is too specific to have a single existing component covering it all, but you can rather easily achieve the effect by combining a number of components.
Anyway, RichFaces has a modalPanel that you can use for the popup. Text fields and buttons are in the standard Faces library and the 'available list of values` can be handled by a selectOneMenu component, which is also in the standard library.
One additional hint, if it's in anyway possible try not to use JSF 1.1. This is an extremely old version where the list of problems is nearly endless. If you are somehow stuck on a very servlet container you should at least use JSF 1.2, but much better is to use the latest 2.1 release.

GUI: Changing panels based on value of combo box

I have a question about GUI design, specifically with Java Swing and creating clean separation between presentation and model.
It's a bit difficult to describe, but essentially we have lots of reference data in our system (i.e. that would correspond to lookup tables in the DB). We want people to be able to edit them all from one screen.
So, in an ideal world what we'd like is a combo box in the top-left corner with a list of 'types' of reference data (so each corresponding to one table in the DB).
Then, when selected, a list of the data is populated below, also a filter (or search box). When one of these items is selected, the panel to the right is activated which will allow the actual data to be edited.
Now, here's the problem: each type of data we need to edit is different, so it has different fields etc. We could go with a generic solution but I'm not really a fan of them - there are lots of different validation rules for each etc, even for different clients, and it would be a nightmare to manage.
We're using the Presentation Model pattern to achieve some degree of separation between GUI code and the model but I can't think of a clean way of doing this which doesn't somehow blur the line of responsibilities a bit.
What are the ways you have solved problems like this?
[Note: apologies for the long question, hope it's understandable, I can re-phrase if necessary]
You could use the Factory Pattern to create a UI widget for the element that you are selecting. You could also use it to create a validation rule object depending on the type. This would give you some of the flexibility you desire.
So you can have something like:
IWidget widget = UIFactory.createFor(myObject.getType())
That can be invoked on the selection event to create the right widget to edit the selected element.
The IWidget could have methods such as:
validateData()
refreshData()
setDataElement(IDataElement element)
That would allow you to treat all UI widgets generically, but still have a special UI widget for each element type. I am assuming that the elements that you are selecting from the table all implement some IDataElement interface that contains the getType() method.
I used this solution tied together with the Eclipse Extension mechanism to plug-in new UI elements into my "base" solution, to have an extensible core and a high level of reuse. You could achieve something similar by injecting types and widgets into your factory, either manually or with Spring.
If you dont want to go down the generic path, you could have your model hold a mapping of combobox item -> panel name for use with a CardLayout. You could then create custom panels for the editing each of the reference data types. When the combo box selection is changed, you can save the current state in your model, request the panel name of the current selection, prepare your next panel for display and then have your CardLayout show it.

Categories