I think removing the conditional that you suggest will have other repercussions. I will look further at this, but it will probably be a few days.
john mcnally Rodney Schneider wrote: > > Hi Edmund and John! > > I have sent two emails to this list regarding this bug in Intake and no-one > has replied yet :( It exists in both the most recent Turbine 2.2 code and > the most recent CVS version of Fulcrum. > > I'll try to explain myself a bit better this time as maybe the bug report I > sent wasn't clear. See this message... > > http://www.mail-archive.com/[email protected]/msg06959.html > > > > > I have got a problem with the rules for checking field values in > > > > intake. Somehow I cannot check for empty fields. I define the rule as > > > > explained in the docs like this: > > > > > > > > .. > > > > <field name="PersonName" key="personname" type="String"> > > > > <rule name="minLength" value="1">Bitte geben Sie den Nachnamen > > > > an.</rule> </field> > > > > .. > > > > > > > > When I leave the field empty, intake does not report an error. > > > > (isAllValid() still returns true) > > > > > > not sure why this does not work. > > If a browser submits a form with an empty text field (with, say, the > parameter name="foo"), then the request parameters will come in in the form > "?foo=&bar=..." etc., and both javax.servlet.HttpServletRequest and > org.apache.turbine.util.ParameterParser will report that the parameter > "foo" is present with the value "" (the empty string). However, > org.apache.turbine.services.intake.model.Field will treat this field as if > it is not present at all: specifically, in the method validate() is the > following code: > > stringValue = pp.getString(getKey()); > if ( stringValue.length() == 0 ) > { > set_flag = false; > } > > Thus, there is no way to distinguish between an empty field and a field that > is not present in the HTML form at all. > > I am happy to generate a patch that removes the above check, but I am not > sure if this will affect the rest of the Intake code... > > > > > I have experimented a bit with intake, and other rules actually do work > > > > as expected, if the field value is not empty. It seems the rules simply > > > > bypassed for empty fields and no checks are applied. So I also tried > > > > setting the required messsage: > > > > > > > > .. > > > > <field name="PersonName" key="personname" type="String"> > > > > <required-message>Bitte geben Sie den Nachnamen > > > > an.</required-message> </field> > > > > .. > > > > > > > > Again, no error when I leave the field empty. Is this a bug in the > > > > intake service (included in TDK 2.1 release) or am I doing something > > > > wrong? > > See above. > > > > <required-message> is to provide a message that is to be displayed if > > > the field is declared as required and the field is empty. It does not > > > make the field required. > > > > > > <rule name="required" value="true">Bitte geben Sie den Nachnamen > > > an.</rule> > > > > > > should work, though i have not looked at what's in 2.1 for a while. > > > > Thanks for the quick reply. That rule actually does seem to work (though I > > cannot find anything about a rule with name "required" in the intake docs > > at > > http://jakarta.apache.org/turbine/turbine-2/services/intake-service.html). > > The "required" rule does work, but this doesn't help in all situations. One > simple example is an "Edit User Profile" form which contains an "Email > Address" field that is not required and a "Work Phone Number" field that is > required. When a user first registers, they type in a valid email address in > the "Email Address" field and their current work phone number in the "Work > Phone Number" field. Then they change jobs, so they go to the Edit User > Profile page, empty the email address field, edit the work phone number field > (but accidentally type a 'abc' instead of a valid number) and submit the > form. Intake finds the the Work Phone Number field is invalid so it > redisplays the page containing the form with the appropriate error message. > HERE IS THE PROBLEM.... the email address field is pre-populated with the > old email address even though the user had previously emptied it!! > > This happens because Intake doesn't disinguish empty fields from fields that > are not present in the form at all. See my other email for more information. > > > A bit odd is, that the isAllValid() method still returns true, but lateron > > when I try to assign the fields to the proper data object (using the > > group.setProperties() method) an exception is thrown (message: "Attempted > > to assign an invalid input"). > > > > Maybe I can figure out another way to check the field validity (either > > that, or I will have to watch for that exception). > > I think the abovementioned code should be removed from > org.apache.turbine.services.intake.model.Field and > org.apache.fulcrum.intake.model.Field but, again, I am not sure whether other > code in Intake relies on the above check or whether existing applications > that use Intake will be affected. > > If you want me to submit a patch, please let me know. > > Thanks, > > -- Rodney > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
