[
https://issues.apache.org/struts/browse/STR-1649?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul Benedict closed STR-1649.
------------------------------
Resolution: Implemented
Assignee: (was: Struts Developers)
The reporter misunderstands the page attribute. Fields attached to a page
number are triggered for validation when the form's page is equal or greater
than the specified page of the field. He wanted to not redefine the field for
each page, but he doesn't have to. The validator already allows this.
> [validator] page attribute in the Validation Config file
> --------------------------------------------------------
>
> Key: STR-1649
> URL: https://issues.apache.org/struts/browse/STR-1649
> Project: Struts 1
> Issue Type: Improvement
> Components: Core
> Affects Versions: 1.1 Final
> Environment: Operating System: All
> Platform: PC
> Reporter: Steve A. Hamilton
> Priority: Minor
> Attachments: Field.java, JavascriptValidatorTag.java, Validator.java,
> validator_1_1.dtd
>
>
> This is more of an enhancement:
> We should be allowed to set the page attribute with comma-seperated pages so
> that we do not have to define the same field validation more than once in a
> form. Something like the following:
> <field property="description" depends="maxlength" page="1,2">
> <arg0 key="resource.description"/>
> <arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
> <var>
> <var-name>maxlength</var-name>
> <var-value>255</var-value>
> </var>
> </field>
> The following could be done to do this:
> CHANGE TO JavascriptValidatorTag.java
> // Skip indexed fields for now until there is a good way to handle
> // error messages (and the length of the list (could retrieve from scope?))
> StringTokenizer st = new StringTokenizer(field.getPage(), ",");
> boolean include = false;
> while(st.hasMoreTokens()) {
> if(page.equals(st.nextToken())) {
> include = true;
> }
> }
> if(field.isIndexed() || field.getPage() != page
> || !field.isDependency(va.getName())) {
> continue;
> }
> Of course, page would have to be changed to a String in both Field and
> JavascriptValidatorTag for this to work.
> An even better idea would be to add the following functionality to Field:
> int[] pages = new int[] {0};
> public void setPages(String pages) throws NumberFormatException {
> if(pages != null && !pages.equal("") && !pages.equals("0")) {
> StringTokenizer st = new StringTokenizer(pages, ",");
> pages = new int[st.countTokens()];
> for(int i = 0; i < pages.length; i++) {
> pages[i] = Integer.parseInt(st.nextToken());
> }
> }
> }
> public int[] getPages() {
> return pages;
> }
> public boolean containsPage(int page) {
> for(int i = 0; i < pages.length; i++) {
> if(page == pages[i]) {
> return true;
> }
> }
> return false;
> }
> Then, change JavascriptValidatorTag.java to:
> // Skip indexed fields for now until there is a good way to handle
> // error messages (and the length of the list (could retrieve from scope?))
> if(field.isIndexed() || field.getPage() != page || !field.containsPage(page)
> || !field.isDependency(va.getName())) {
> continue;
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.