XML configuration of Zend_Form: child nodes and attributes not always equal? - zend-form

A set of forms (using Zend_Form) that I have been working on were causing me some headaches trying to figure out what was wrong with my XML configuration, as I kept getting unexpected HTML output for a particular INPUT element. It was supposed to be getting a default value, but nothing appeared.
It appears that the following 2 pieces of XML are not equal when used to instantiate Zend_Form:
Snippet #1:
<form>
<elements>
<test type="hidden">
<options ignore="true" value="foo"/>
</test>
</elements>
</form>
Snippet #2:
<form>
<elements>
<test type="hidden">
<options ignore="true">
<value>foo</value>
</options>
</test>
</elements>
</form>
The type of the element doesn't appear to make a difference, so it doesn't appear to be related to hidden fields.
Is this expected or not?

As it was rather quiet on here, I took a look further into the source code and documentation.
On line 259 of Zend_Config_Xml, the SimpleXMLElement object attributes are converted to a string, resulting in:
options Object of: SimpleXMLElement
#attributes Array [2]
label (string:7) I can't see this because
value (string:21) something happens to this
becoming
options (string:21) something happens to this
So, I hunted through the documentation only to find that "value" is a reserved keyword when used as an attribute in an XML file that is loaded into Zend_Config_Xml:
Example #2 Using Tag Attributes in Zend_Config_Xml
"..Zend_Config_Xml also supports two
additional ways of defining nodes in
the configuration. Both make use of
attributes. Since the extends and the
value attributes are reserved keywords
(the latter one by the second way of
using attributes), they may not be
used..."
Thus, it would appear to be "expected" according to the documentation.
I'm not entirely happy that this is a good idea though, considering "value" is an attribute of form elements.

Don't worry about this. The reserved keywords were moved to their own namespace, and the previous attributes were depricated. In Zend Framework 2.0 the non-namespaced attributes will be removed so you can use them again.

Related

Can I iterate form-lists in Moqui?

Is there a way to do the following in Moqui?
Say I have a list of parent categories (or classifications etc.)... Taking Request categories:
<entity-find entity-name="mantle.request.RequestCategory" list="parentCategoryList">
<econdition field-name="parentCategoryId" operator="is-null" />
</entity-find>
And I want to use 'parentCategoryList' to produce a sub-list for EACH parent category, to display separate form-lists on screen:
Something like:
<iterate list="parentCategoryList" entry="thisCategory" >
<entity-find entity-name="mantle.request.RequestCategory" list="categoryList">
<econdition field-name="parentCategoryId" from="thisCategory.requestCategoryId" />
</entity-find>
<!-- I include the following only to give an idea of what I am trying to do.
It is incorrect and incomplete -->
<script>listOfLists.add(categoryList)</script>
</iterate>
Then use that 'listOfLists' to iterate a form-list, supplying the form-list 'name' and 'list' sequentially for each list in the list. (I know you can't use iterate outside of actions, and you can't use forms inside of actions.)
I may well be thinking about this in the wrong way.
You can iterate within the screen.widgets element, just use section-iterate. There are limitations to how much you can nest these (the current template macros for XML Screens/Forms only support so much), but you can do quite a bit. There are example of this in SimpleScreens, like the OrderDetail.xml screen iterating over order parts.

Struts 2 property not being read from properties file

After following the struts 2 web pages and numerous examples, my application still will not pick up values from the struts.properties file.
I am trying this in order to give some values a money type format:
<s:property value="getText('struts.money.format',{value})" />
My struts.properties file which is under WEB-INF/classes and therefore visible has the following single line
struts.money.format= {0,number,\u00A4##0.00}
I get the string struts.money.format printed to the screen. If I change the first parameter of the getText call, the new string I put also will get printed instead of a true lookup happening.
If I do <s:property value="value" /> I will get back a proper number. If I drop the second argument on the getText call, I would expect to get back the right hand side of the assignment in the properties file, but i get the same struts.money.format back.
I am using Tomcat 6 with Struts 2.2.1.1. Is there an additional part of the puzzle I am possibly leaving out?
So in my struts.xml file, I put this line
<constant name="struts.custom.i18n.resources" value="struts" />
It needs this to know that I am trying to use a struts.properties file. I had assumed that by default a file named struts.properties was along the chain of places to look for a constant such as this. Only if you named it something else did you need to specify that. Even though it is in WEB-INF/classes which is recommended by the Struts 2 documentation, it just simply was not looking in this file.
EDIT
For what it is worth, I also had to modify my struts text tag like so
<s:property value="getText('struts.money.format',{#java.lang.Double#valueOf(value)})" />
Actually, value should have been a BigDecimal, but it was being treated at the view level here as java.lang.String. The problem is that some of the String objects had exponential formatting (like 1.642E07 or something to that effect) and the struts formatter could not handle the exponential formatting. The valueOf eliminates this exponential fomatting

Get an XML Element via XPath when attributes are irrelevant

I'm looking for a way to receive a XML Element (the id of an entry) from a YouTube feed (e.g. http://gdata.youtube.com/feeds/api/users/USERNAME/uploads).
The feed looks like this:
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:yt="http://gdata.youtube.com/schemas/2007" gd:etag="W/"DUcFQncyfCp7I2A9WhVUFE4."">
<id>tag:youtube.com,2008:user:USERNAME:uploads</id>
<updated>2012-05-19T14:16:53.994Z</updated>
...
<entry gd:etag="W/"DE8NSX47eCp7I2A9WhVUFE4."">
<id>tag:youtube.com,2008:video:MfPpj7f6Jj0</id>
<published>2012-05-18T13:30:38.000Z</published>
...
I want to get the first tag in entry (tag:youtube.com, 2008 ...).
After googling for some hours and looking through the GDataXML wiki, I'm clueless because neither XPath nor GData could deliver the right element.
My first guess is, they can't ignore the attributes in the feed and entry tags.
A solution using XPath would be great, but one in Objective-C is equally welcome.
You might be having an issue trying to get XPath to work because of the default namespace.
If you just want the first tag in entry, you can use this:
/*/*[name()='entry']/*[1]
If you want the first id specifically, you can use this:
/*/*[name()='entry']/*[name()='id'][1]
Also if you can use XPath 2.0, you can skip the predicate entirely and use * for the namespace prefix:
/*/*:entry/*:id[1]

Struts 1.x tags usage question

I have a jsp page with the tags:
<logic:iterate id="var" ...
....
<bean:write name="var" property="p1" ...
etc.
And I need, on each iteration, to generate a href composed from the various bean's properties. I even need to URLEncode some of them so the link works.
Something like
<logic:iterate id="var" ...
....
<html:link action="otheraction.do?_X_
<bean:write name="var" property="p1" ...
etc
where X is generated by collecting the bean's properties; something like
String X="p1="+URLEncode(p1)+"&p2="+SimpleDateFormatof(p2)+"&p3="+p3;
How can I do that ?
Thanks in advance.
Better to make one POJO class.
1. Assign all your values to the object in Action which is being called before your jsp page comes in the picture.
2. Keep the object of POJO to request attribute.
3. Get the value from request attribtue on JSP using <bean:write> tag.

Refining my Dojo/Dijit NumberTextBox numeric validation

I have the following code:
<input type="text" dojoType="dijit.form.NumberTextBox" size=8
constraints="{min:0,max:100000,places:0}"
id="orgNumberOfStudents" name="orgNumberOfStudents"
required="true" invalidMessage="Integer between 0 and 100,000"
value="">
Questions:
1) How do I set the width of the box? Do I have to do it in a style tag or a CSS? Is the traditional "input size" tag ignored?
2) The above sample shows the error when I type in a non-numeric value. But if I tab over the field and don't fill in anything, it's still blank. Is there a quick way to enforce the validation when I click the submit button? Do I need a Dijit submitt button? Do I need to write more JavaScript to make this happen? How does the required="true" actually occur?
(One get-around is to set the value to 0, but I'd rather force the user enter a value rather than just defaulting it).
Thanks,
Neal Walters
You should be able to use both CSS and traditional INPUT attributes like "maxLength" on your NumberTextBox by passing them in to the Widget's constructor. maxLength is available on all dijit.form.TextBox subclasses, but is probably less useful here since you have control over things like min/max and the actual number format.
Yes, you can always write your own JS to test "isValid()" on your widget instance before submission, e.g. in an HTML FORM onSubmit handler, or you could use dijit.form.Form which will check validity for you. The widget itself is only responsible for visual representation of its own validity, according to the options chosen.
HTH