This is simple question but there's No answer found on the Internet.
Ok, some widgets such as CheckBox have a method called myCHeckBox.setFormValue(text); so I take advantage of this method to store the unique ID into a CheckBox so that later on I just myCHeckBox.getFormValue(); to retrieve back the unique value.
However, there's no setFormValue on GWT Panel?
So if we want to store a unique value into a Panel (for example, FlowPanel, VerticalPanel)?
Then Which method can i use to do that?
The way I see it what you are really trying is to extend the purpose of the Panel. I cannot see why you would want a unique identifier, as the object of the Panel is as unique as it guess but that's not the point here.
Since you want to extend the Panel do just that. Extend the corresponding class and give it a unique value, implement the corresponding getters and setters and then you are set. It is as simple as that
class AbsolutePanelUnq extends AbsolutePanel
{
private int uniqueId;
public getUniqueId(){
return uniqueId;
}
public setUniqueId(int uniqueId)
{
this.uniqueId = uniqueId;
}
}
Then create the object and do whatever you need.
Best way I can suggest:
Public class myPanel extends Panel {
private myUniqueValue;
//Getter setter for myUniqueValue
}
Related
I would like to go through all fields in form data.
I know that in form I could do something like this :
// Go through all fields with IFormFieldVisitor
box.visitFields(new IFormFieldVisitor() {
#Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (field instanceof MyClass) {
...
}
return true;
}
}, 0);
but form data doesn't have this options. How to do this in form data.
You can obtain them using
AbstractFormData.getFields to obtain the top-level fields. If you need nested fields as well, have a look at the more complex AbstractFormData.getAllFieldsRec().
AbstractFormData.getAllProperties to obtain properties that you have defined by annotating the getters and setters with #FormData
That was the simple case.
Now, if you are using the Scout Extension mechanism to add new elements to an existing form (and it's formdata), you will have to take those contributions into account.
If you need to do this, you can refer to the source code of the AbstractForm.importFormData to see how Scout implements this.
in my current project I have to render items in a CellTable received via a RPC call. The columns must be created dynamically and the column types are unknown at compile time.
From the server side, I send a list of the following class to define a row in the table:
public class TableRowDTO implements IsSerializable {
private List<IsTableItemDTO> tableItemDTOs;
public TableRowDTO() {
tableItemDTOs = new ArrayList<IsTableItemDTO>();
}
// getters & setters ...
}
Where each row will contain an item implementing IsTableItemDTO which is a marker interface:
public interface IsTableItemDTO extends IsSerializable {}
Implementing classes depict the actual controls/information to be shown in cells like:
public class TableDateTimeDTO extends IsTableItemDTO {
private Date valueDate;
// ... other fields not necessary for the table
}
Or also:
public class TableCheckBoxDTO extends AbstractTableItemDTO {
private boolean checked;
// ... other fields not necessary for the table
}
And also:
TablePasswordDTO extends AbstractTableItemDTO {
private String valueText;
// ... other fields not necessary for the table
}
Therefore, what I want to do for example in the case I receive a List with {TableCheckBoxDTO, TableDateTimeDTO, TablePasswordDTO} is to render a CellTable with the corresponding widgets.
I've seen this and this, but I don't see how to apply any of the examples to my case especially because I cannot use thigs like Column as I don't have my ContactInfo before hand.
Thanks
You can use the marker interface IsTableItemDTO together with instanceof() and dynamic casts to have a generic Column/Cell.
There are 2 ways:
Create a Composite Cell and add all possible cell types and then display based on what specific sub-type your isTableItemDTO is.
Create a custom cell and render the input (checkbox, text) based on the specific type of your marker interface
I used Jet table (https://code.google.com/p/gwt-jet/) in one of my earlier projects. I believe it has the features you are looking for.
I would like my uiBinder to use a ClientBundle which will provide some runtime customized labels. Kind of a TextResource but not from a text file !
I tried with GwtCreateResource but from the DevGuide it seems like it's not possible. Am I right ? (create() and name() are the only methods available)
What I would like to achieve is something like this:
client bundle:
public interface MyWidgetResources extends ClientBundle {
GwtCreateResource<WidgetLabels> labels();
#Source("lol.css")
CssResource style();
}
labels class:
public final class MyWidgetLabels {
public String title() {
return load("mywidget-title");
}
public String banner() {
return load("mywidget-banner");
}
private String load(String key) {
// load from external..
}
}
uiBinder:
<ui:with type="com.package.MyWidgetResources" field="res"/>
<gwt:SimplePanel>
<gwt:Label text="{res.labels.title}"></gwt:Label>
<gwt:Label text="{res.labels.banner}"></gwt:Label>
</gwt:SimplePanel>
My code looks like this already but res.label.title does not work because GwtCreateResource can only serve as class instantiator (res.labels.create().title()).
Is there a solution for me ? Maybe with a custom ResourceGenerator ?
As long as MyWidgetLabels can be created by GWT.create, you can put anything you want into that type, and you can make it behave however you'd like. You will need the create reference in your uibinder as you suggested at the end of the post to actually build the object, so your lines will look about like this:
<gwt:Label text="{res.labels.create.title}"></gwt:Label>
Each . separated piece (except the first, which is a ui:field/#UiField) is a no-arg method to be called - you declared labels() in MyWidgetResources, create() already existed in GwtCreateResource, and you created title() in your own MyWidgetLabels type.
Since that first piece is a ui:field/#UiField, you could have another that references res.labels.create as something like labels so that later you could instead say:
<gwt:Label text="{labels.title}"></gwt:Label>
Finally, yes, you could build your own ResourceGenerator which would enable you to do whatever you wanted to emit the type in question, as long as you extended the ResourcePrototype type and had a getName() method.
I have a model called Field which has id and label.
I have defined PropertyAcess as below and it works. I would like to change it in such a way that I can show label based on condition ie if field.getLabel() is null, use field.getId() as label. How can I acheieve that
interface FieldProperties extends PropertyAccess<Field> {
ModelKeyProvider<Field> id();
LabelProvider<Field> label();
#Path("label")
ValueProvider<Field, String> labelProp();
}
Thanks
The PropertyAccess tool is meant to make it easy to quickly build ValueProvider, ModelKeyProvider, and LabelProvider instances that are based on a specific getter/setter on a bean-like object. If you don't want just access to a single property, then implement the interface directly.
In your case, since you want a LabelProvider that returns getLabel() unless it is null, then getId(), you might do something like this:
public LabelOrIdLabelProvider implements LabelProvider<Field> {
#Override
public String getLabel(Object item) {
return item.getLabel() == null ? item.getId() : item.getLabel();
}
}
If you want custom behavior, build it out yourself to do exactly what you need. If you just want the simple behavior of reading a single getter, the PropertyAccess is there to help save you a few lines of code.
I have a domain object which has a collection of primitive values, which represent the primary keys of another domain object ("Person").
I have a Wicket component that takes IModel<List<Person>>, and allows you to view, remove, and add Persons to the list.
I would like to write a wrapper which implements IModel<List<Person>>, but which is backed by a PropertyModel<List<Long>> from the original domain object.
View-only is easy (Scala syntax for brevity):
class PersonModel(wrappedModel: IModel[List[Long]]) extends LoadableDetachableModel[List[Person]] {
#SpringBean dao: PersonDao =_
def load: List[Person] = {
// Returns a collection of Persons for each id
wrappedModel.getObject().map { id: Long =>
dao.getPerson(id)
}
}
}
But how might I write this to allow for adding and removing from the original List of Longs?
Or is a Model not the best place to do this translation?
Thanks!
You can do something like this:
class PersonModel extends Model<List<Person>> {
private transient List<Person> cache;
private IModel<List<String>> idModel;
public PersonModel( IModel<List<String>> idModel ) {
this.idModel = idModel;
}
public List<Person> getObject() {
if ( cache == null ) {
cache = convertIdsToPersons( idModel.getObject() );
return cache;
}
public void setObject( List<Person> ob ) {
cache = null;
idModel.setObject( convertPersonsToIds( ob ) );
}
}
This isn't very good code but it shows the general idea. One thing you need to consider is how this whole thing will be serialised between requests, you might be better off extending LoadableDetachableModel instead.
Another thing is the cache: it's there to avoid having to convert the list every time getObject() is called within a request. You may or may not need it in practice (depends on a lot of factors, including the speed of the conversion), but if you use it, it means that if something else is modifying the underlying collection, the changes may not be picked up by this model.
I'm not quite sure I understand your question and I don't understand the syntax of Scala.
But, to remove an entity from a list, you can provide a link that simply removes it using your dao. You must be using a repeater to populate your Person list so each repeater entry will have its own Model which can be passed to the deletion link.
Take a look at this Wicket example that uses a link with a repeater to select a contact. You just need to adapt it to delete your Person instead of selecting it.
As for modifying the original list of Longs, you can use the ListView.removeLink() method to get a link component that removes an entry from the backing list.