I have a ComboBox defined as follows:
private final ComboBox classification = new ComboBox( "Class" );
classification.addItem("C");
classification.setItemCaption("C", "Company");
classification.addItem("S");
classification.setItemCaption("S", "Supplier");
classification.addItem("U");
classification.setItemCaption("U", "Customers");
classification.setRequired(true);
classification.setRequiredError("A user class must be chosen!");
classification.setFilteringMode(FilteringMode.CONTAINS);
classification.setTextInputAllowed(true);
Whenever I select any value from the dropdown, it immediately clears what I select. I don't even see it in the "ValueChange" listener.
What is weird is that I copied this form from another one that works perfectly, with a country dropdown. I am NOT picking an invalid value from the dropdown. Any idea what is happening?
If not, any idea where I would set a break point in debugger to see where it is getting cleared in ComboBox code? I tried this once, but sort of got lost in the details.
Ok, I found the answer to my own question. In my case, my problem was caused by the wrapper bean I was binding the fields too. My bean wraps two "sub-beans", if you will, one for input from an XML, one for output to an XML. The one for "input" should be filling the form ( calls "get" methods ), but the one for "output" should filling the data from the form ( calls "set" methods ). This is obviously not ideal, but this is the API I am stuck with. To fix it, I just made sure that all wrapper "get" methods checked "input" bean first, then "output" bean. For the "set" methods, I just made sure I set both the "input" and "output" beans. Like I said, not ideal.
To summarize: If you see your ComboBox value going away, making sure the bean you are binding to does not undo whatever the ComboBox sets in the corresponding "setter" and "getter" ( under the hood, I believe it sets it, then gets it again ).
Hopefully this helps someone not make the same mistake.
Related
to use some browser's capability to "autofill" (like "Ah, this input is called 'firstname', let me offer my user all the firstnames he entered elsewhere"), we would like to at least (since the id is random anyway) set the name attribute of the input fields. Unfortunately, the documentation of InputElement.setName says...
Don't use this method if your
application is purely based on ZK's
event-driven model.
So, big question: Will this cause somehow troubles if I use this method? Or is there another way to put the name of the input element into the resulting html?
I think the warning in the API is meant to tell you, that ZK does not consider this attribute except of setting it into the rendered html.
Maybe it's there to prevent developers from using name instead of ZK's id property and thus failing to correctly bind components.
I never encountered a problem when using it.
I have a form with some checkboxes and spinners. They all have ActionListeners\ChangeListeners assigned to them, so each time you change some element, the program launches a create() method, which gathers all the values from the entire form and puts them into object, which can be saved to disc later.
But now I'm trying to make the program to load that object from file and update the interface according to what has been loaded. This is where problems arise. After the program has loaded the object, it tries to update the elements of the form, but just as it changes the first one, ActionListener is triggered and it gathers all the values from the form and overwrites the object that was loaded before.
What would be a good way to solve this problem?
Right now I'm thinking about creating a global variable to "switch off" the create() method when I load the object (that is to create a flag that stops action listeners). But I'm not sure if this is a good idea.
Instead of flag maybe think of creating an enumeration called FormState to represent states of the form e.g. READ and EDIT. You can toggle the state of the form before and after persisting values.
Solved it by adding a private boolean variable which is changed to false when interface is being updated.
I have some classes with fields and getters/setters and I want to display the fields of the class in a Swing application.
The name of each field should be dosplayed in a Label and the value should be displayed depending on the type of the value, i. e. String uses a TextField, List uses a ComboBox and so on.
One difficulty is that the class can contain fields, which also need to be treated this way itself.
Is there a recommended/standard way of doing that?
I looked a bit into java.beans but I'm not really sure if it isn't primarily used when the class is a Swing component itself.
Another option is to use PropertySheet component from L2FProd. From you description it should do exactly what you wanted.
It wasn't updated for a long time but works well.
I don't think there is an automated way to accomplish this. In fact I think you might even be approaching it incorrectly. What if you List contains objects other than Strings for example, how is a JComboBox going to break this out? I would suggest just using a JTable and putting the name in the first column and the value in a second column.
You could add #Annotations to your fields you want to examine and display in the GUI. In every case you have to use reflections to access and find all the fields you want to display. I think you have to add a custom logic to the databinding which examines a given class for it's fields (maybe filtered with a #Display annotation or stuff like this).
This should be very easy to implement, you can rely on the POJO Bean definition and access all the fields over getter/setter, don't forget to cache the handled classes to avoid circular dependencies of classes.
I hope this helps.
There is ReflectionUI. It can display primitive values objects and lists by just using reflection. It works well with getter/setter properties.
In my domain I have objects that are constantly being updated by a separate process, and I want a PropertySheetView to display the changing properties. The current implementation is set up such that the underlying domain model object is immutable, and thus when it changes, there is a new object published with a corresponding ID. At that point, my Node wrapping the object has subscribed, gets the updated object with a matching ID, and recreates the Sheet (via createSheet()) and calls setSheet with the updated information. This works fine at always showing the most recent version of the domain model object.
However, some of the properties are not read-only, but instead can be set. I would like to lock the sheet from being updated / overwritten, on either a row or sheet basis, while a property is being edited. In order to do this I need to listen for edit start and end calls so I can know when it's safe to update the sheet again.
This is crucial for my application; as it stands now you can't get through entering a new value before the sheet is refreshed and your edit goes away.
If it matters, I'm using a custom PropertyEditorSupport, but the default InplaceEditor.
I've done a lot of searching through the NetBeans source and I don't see any exposed API settings to listen for this stuff.
SheetCellEditor (org.openide.explorer.propertysheet) exposes an addCellEditorListener method, but A) I can't figure out how I would get a handle on the SheetCellEditor instance, and B) the methods exposed by SheetCellEditor are editingCanceled and editingStopped - there is no callback for editing started! Seems very silly. The SheetTable and BaseTable would expose this property too, as they extend JTable, but I cannot figure out how to get a handle to them either.
I notice that the CellEditor interface requires the method isCellEditable(), which supposedly returns true if the cell can be edited, and thus the editing begins. But again, this is implemented by the SheetCellEditor which is not a public class, and I don't know how to get a reference to it.
Thank you for your help.
The best solution I could come up with was as follows:
Create a custom property editor. Make that editor implement InplaceEditor. Return a StringInplaceEditor which is a textfield. Attach a focus listener to that textfield. When focus is in the text field, it is being edited. Otherwise it is not.
And my confusion with JSF continues. This is a continuation of a question asked yesterday, but I feel it warrants a new question. I have a single seam component that expects a URL parameter to be injected for retrieving a List<String> from a method. This works perfectly on the first navigation to the page. The List is used to display many different selectOneRadio groups that populate a <h:form/>.
Now on the submit, I cannot get the URL parameter to be injected or otherwise set on the component! Adding <h:inputHidden/> causes FacesExceptions to be thrown.
Then I tried setting the List as an instance variable on the object, and when the subsequent call is made on the submit (which I also do not understand why that is done) I check to see if the variable is non-null: if it isn't, return it.
Now I found that a new instance of the component is created on submit!!!
getList() called
this.toString(): .BeanAction#5fd98420
#### This is when submit is clicked
getList() called
this.toString(): .BeanAction#22aacbce
The component has the following annotations:
Stateful
#Scope(ScopeType.CONVERSATION)
#Name("bean")
#Restrict("#{identity.loggedIn}")
Can someone explain why there is a new instance of the component created?
I'm really not quite sure how to go about handling this. I thought the hidden parameter would work, because that is how I would do it with straight HTML, and I'm a little surprised that its not working for JSF/Seam.
I hit upon the solution, but I still dont understand why it is required. By adding <S:conversationId/> to the <h:commandButton/> tag I am now getting the conversationId propagated across the form submit.
However, the seam documentation states:
If you don't do anything special, a non-faces request (a GET request for example)
will not propagate the conversation context and will be processed in a new
temporary conversation.
Which means Seam/JSF was treating my form submit as a "non-faces request". Why is that?
When you enter the page (or after the submit), do you see a conversation id in the url? I am concerned that perhaps the Seam Conversation is not being initialized correctly.