So I create a radio group using this PdfFormField.createRadioButton() then calling the setFieldName().
However, the PdfAnnotation does not show any keys that stores the field name. I looked at the other dictionaries inside the PdfAnnotation but could not find any.
reader.getAcroFields().getFields().keySet() does list the field names of the form fields but I wish to ask if there is any way via PdfAnnotation?
I tried to put a custom PdfName inside the radio group object but it does not show up in the PdfAnnotation's dictionary.
You are confusing the concept of an annotation (link annotation, file attachment annotation, widget annotation,...) and a form field (text field, choice field, button field, signature field).
In iText 5, annotations are dealt with in a class named PdfAnnotation; form fields are dealt with in a class named PdfFormField. You are trying to do something that is specific for a PdfFormField using the class PdfAnnotation. That's wrong.
I understand the root of the confusion: every visible form field corresponds with at least one widget annotation. Most of the visible form fields correspond with exactly one widget annotation. That's why we made a design choice in iText 5 to have PdfFormField extends PdfAnnotation.
This design choice is in line with the PDF specification where it says that field dictionaries of fields that correspond with a single widget annotation may be merged into a single PDF dictionary.
In practice, you will find PDF dictionaries in a PDF that combine entries typical for a widget annotation dictionary and a field dictionary. (That also explains why there's a getMerged() method in iText: that method gets you the merged dictionary objects.)
I hope this already explains part of your problem. You seem to have another problem too, but I don't understand what you want to do. Please clarify using references to ISO-32000-1 so that people can understand which technical feature you are trying to implement.
Related
I am trying to subsequently manipulate the menus and tabs of a w2ui application.
In order to implement a generic solution, I added an additional attribute (zndesktop) to the related elements. Now I am looking for a generic method which gives me an array of all objects having this attribute.
Of course, I can hardcode such a query. But I am asking if there is an generic approach (for example w2ui.objects) which would return an array of all UI objects created for the application (recursive search)
w2ui objects are actually stored directly in the global w2ui object using their name, until you destroy them.
Example: if you create a grid with
$('#grid').w2grid({
name: 'my_grid',
...
});
Then you can access it with w2ui.my_grid or w2ui['my_grid'].
Of course you can also iterate the w2ui object (or rather its properties) just like any other JS object.
I have a custom widget (OrderItem) in a GWT project. This widget has a TextBox. I set it's id to "Navid". But what if I create multiple instances of OrderItem in a panel? The id would be repeated then. This'd make the html invalid.
How do I assign a unique id to the TextBox?
Well, normally, GWT widgets generate their own IDs that will automatically be unique and you would not typically worry about what the ID is. When you say that you are setting the ID of a TextBox, I'm assuming that you're calling something like myTextBox.getElement().setId("Navid").
There are two simple methods I can think of, depending on your use-case. The HTMLPanel class has a static createUniqueId() method on it that you can use either on its own, or to easily create a unique id. Like myTextBox.getElemement().setId("Navid-" + HTMLPanel.createUniqueId()). The only problem with this is that the ID that is generated is not deterministic.
The other common method would be to generate an ID based on the ID of the parent widget. myTextBox.getElement().setId("Navid-" + myTextBox.getParent().getElement().getId()).
However, I'm going to take a guess here and assume that the reason why you're wanting to assign your own custom ID to this widget is so that you can address it from outside of your GWT code, from Javascript, for example, from JQuery. In this case, I would recommend that instead of assigning an ID to it, which has to be unique to be useful, that you instead assign an html class name to the widget's element. You would then address the widget's element relative to the id, or class of your OrderItem's id or class. You can add an html class name to an element as in the example myTextBox.getElement().addStyleName("navid")
So, assuming that you assign an html class of orderItemWidget to the root HTML element of your OrderItem widget, and an html class of navid to the TextBox, you could refer to the textbox from a JQuery with the selector ".orderItemWidget .navid"
This is why GWT makes it doesn't make it that easy to set an ID on a widget. For styling, it makes it much easier to use CSS class names. Actually, there are very few reasons to use an ID to begin with, and almost none for dynamically generated things (like widgets).
Now, to answer your question, browsers tolerate the case of several elements sharing the same ID, and getElementById is defined to return the first of those elements (in document order)
Is it possible to use a variable inside the error message referring to the label of the form element? It's possible to map custom variables like %hostname% (in email validator) and the %value% is also available, but I'd like to have the form label as well.
I could't find it in the ZF codebase, but the use case is for example that the Zend_Validate_NotEmpty can return a message like:
"The field %label% is required and can't be empty"
Instead of:
"Value is required and can't be empty"
I think it's not possible without subclassing the validators. The Zend_Validate classes are not intended to be used with Zend_Form_Element only. Having a %label% in the message would introduce a coupling between both components.
A possible solution could be to create custom validators by extending Zend_Validate_NotEmpty (or whatever validators you are using) and pass the label to the constructor. This way, you could compose the appropriate message every time you instantiate it.
EDIT:
If you follow the method above, you could even define your own %label% "magic variable" and attach it to a member of the class. See the $_messageVariables member in the Example #2 in the Zend Framework documentation: Writing validators
Hope that helps...
I finally went with the decorator. The solution of dinopmi is possible, however you need to inject the label all the times. My error decorator for the form element replaces now the %label% to the real label.
Can one iterate over all the textbox controls defined in a composite widget?
As in I need to extract values of all textboxes to check if they exist - the textboxes should have some data in them.
So I was hoping to have a method like:
for(Widget w: this.getChildren)
{
//if widget is a textbox - check value
}
Composite class does not have a method like getChildren neither a method where I can get elements of a given class - or name and if I get all the elements using NodeList then I need to recursively go until I find a textbox. Is there a more appropriate way to do this?
As the author of the Composite subclass, you can enable this kind of behavior by implementing HasWidgets (or, more specifically, something like getWidgetIterator()).
There's no way to do this for an arbitrary Composite.
This may sound very weird, but let's start with an example:
<my:MagicWidget ui:field="someFieldName" fieldName="someFieldName"/>
It's pretty much asured that we'll always want to have the same value in ui:field and in fieldName. Clearly there is some duplucation in this code, I'd like to avoid it and make the fieldName optional.
So, this is what I have in the widget's code:
#UiConstructor
public MagicWidget(String fieldName) {
this.fieldName = fieldName;
}
But I'd like, if possible to allow this constructor to be optional, and provide an default constructor that would "by magic" find out it's ui:field value:
#UiConstructor
public MagicWidget() {
this.fieldName = /*some magic to get ui:field's value*/;
}
I was wondering if there is a way to get the value of "ui:field" inside my MagickWidget? (The widget extends Composite). I fear this might not be possible, because most of the time it's not so useful, but if anyone has an idea - feel free to share!
PS: I'm using GWT 2.1.0.RC1.
As you may know, the ui:field is there so you can interact with a UI Object in Java code after you've declared it with UiBinder. So, for example, if you add a MagicWidget in a UiBinder template, you can write
#UiField MagicWidget someWidget
in order to be able to interact with it programatically. Having your magic widget aware of the name of the reference that is pointing to it might not be all that helpful (or possible), as you can pass the reference to that specific MagicWidget back and forth between different parts of your application. A single MagicWidget could easily have several references with different names pointing at is simultaneously. That's why it's difficult to pick it out "by magic" at runtime. I realize this isn't much of an issue if you only want this value when the object is constructed, but keep in mind that you're not required to include a ui:field when you add a widget using UiBinder.
Why is it important that the Widget know its field name? Knowing that might make it easier to provide suggestions about other ways to accomplish what you are looking to do.