Thanks a lot for your answer.
I actually figured out the behavior you explain here (after a short night sleep and a lot of debugging;-), and found a solution to my problem. What I actually do is force the component name to the appropriate client ID before I record my error. I do this in my custom validation delegate.

This is not very elegant (I have to use in my listener the same ID allocation algorithm than the form support, to make sure the client IDs are in sync), but it does the job.

Thx again
Ch.

Shing Hing Man a écrit :
When you use a component in a loop, only one instance
of it is used.
The problem is that in the java code of your page, you
can not, as you said,
 reference the second,say,  'component' in the loop.
Each 'copy' of the component in the loop can be
uniquely identified by
getClientId().

Example : .page
        
   <component id="loop" type="For">
        <binding name="source" value="ognl:entries"/>
<binding name="value" value="ognl:entry"/> <binding name="index" value="myIndex"/> </component>


<component id="inputTF" type="TextField"> <binding name="value" value="ognl:entry" /> </component>


.html,
  <span jwcid="loop">
           Entry : <input type="text" jwcid="inputTF"/>        <br>

   </span>

The generated html would be :

           Entry : <input type="text" name="inputTF" value=""
id="inputTF"/>      <br>
Entry : <input type="text" name="inputTF_0"
value="" id="inputTF_0"/>         <br>
Entry : <input type="text" name="inputTF_1"
value="" id="inputTF_1"/>         <br>


----------------
Note that the inputTF, inputTF_0, inputTF_1 are the
unique clientIds.
A possible solution is to use a custom delegate to record the clientId of the component in error, in your
java code.
In the custom delegate, you have your own method public void writeSuffix, to mark the fields in
error.
The following is an example to illustrate the above.
( But I have not put in the error message .)


Shing ========================



public abstract class TestComponentInLoop extends
BasePage implements
                PageBeginRenderListener {

        @Bean(man.custom.MyDelegate.class)
        public abstract MyDelegate getDelegate();

        public abstract String[] getEntries();

        public abstract void setEntries(String[] str);

        public abstract int getMyIndex();

        public abstract void setMyIndex(int ent);

        public void formSubmit(IRequestCycle cycle) {
                // Mark the second inputTF in error             
                MyDelegate delegate = getDelegate();
                delegate.addClientsId("inputTF_0");
        }

        public String getEntry() {
                return getEntries()[getMyIndex()];
        }

        public void setEntry(String str) {
                getEntries()[getMyIndex()] = str;
        }

        public void pageBeginRender(PageEvent arg0) {
                if (getEntries() == null) {
                        String[] entries = new String[3];
                        setEntries(entries);
                }

        }

}

===============

.page :






 <?xml version="1.0"?>
<!DOCTYPE page-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";>

        
<page-specification
class="man.pages.TestComponentInLoop" >
<description>
           Custom validation of a component in a loop
</description>
        
   <component id="loop" type="For">
        <binding name="source" value="ognl:entries"/>
<binding name="value" value="ognl:entry"/> <binding name="index" value="myIndex"/> </component>


<component id="inputTF" type="TextField"> <binding name="value" value="ognl:entry" /> </component>
</page-specification>
==============================
.html




<html>

<head>
  <title>TestComponentInLoop</title>
  <meta name="GENERATOR" content="Quanta Plus">
  <meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body jwcid="@Body">
   <form jwcid="@Form" listener="listener:formSubmit"
delegate="ognl:delegate">
         <span jwcid="loop">
           Entry : <input type="text" jwcid="inputTF"/>        <br>

         </span>

      <input type="submit"/>
   </form>

</body>
</html>


--- Christian Dutaret <[EMAIL PROTECTED]>
wrote:

Hi,

I have a form which contains input fields (e.g.
PropertySelection components) within For loops.
I need to perform some custom validation, which
sometimes acts across several fields. I usually implement single-field validation through validators, and cross-field validation in the listener (this is necessary because i cannot validate against other fields if the corresponding property value has not been set yet)
The problem I am facing with fields nested in loops
is that i do not have access to the corresponding components (I need the component to pass to the validation delegate) through getComponent(id). Only the last iteration component is available, the previous one
are gone.
Is there any way to retrieve all components within
the For loop?

I hope this is clear enough, not really easy to
explain...

Any help appreciated
Thx
Ch.


---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]




Home page :
  http://uk.geocities.com/matmsh/index.html


                
___________________________________________________________ Inbox full of spam? Get leading spam protection and 1GB storage with All New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to