You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Trussell David N <Da...@irs.gov> on 2004/03/29 20:29:20 UTC
Implementing a Foreach
I'm fairly new to Java and even newer to Tapestry. I've searched the
archives, read (part of) "Tapestry In Action" and played around with the
example snippets in Tapestry->Doc->ComponentReference->Foreach. As much as I
hate to admit it, I'm lost. Any help would be appreciated. Our story thus
far:
User enters identifier and is identified as a "new user" then
cycle.activate("NewUser").
NewUser.html will contain a "@Foreach" component for each row returned from
the database. Just display at render time, nothing fancy, no tables, etc.
NewUser.page contains:
<page-specification class="ol5081.NewUser">
<property-specification name="rulesList" type="java.util.ArrayList"
persistent="yes" />
<property-specification name="rule" type="ol5081.sqlj.Rules" />
</page-specification>
"Rules.java" contains SQLJ code (not sure that's relevant) that populates
the ArrayList with rows returned from a query.
NewUser.java contains:
package ol5081;
import org.apache.tapestry.html.BasePage;
import java.util.*;
public abstract class NewUser extends BasePage {
public abstract ArrayList getRulesList();
public abstract ArrayList setRulesList(ArrayList value);
}
I've tried quite a few different approaches with rather ugly results.
Thank you all very much.
Dave
Re: Implementing a Foreach
Posted by John Studarus <st...@jhlconsulting.com>.
If I answer your question do I get a deduction on my taxes?
(Poster is from irs.gov)
Give this is a try...
John
NewUser.page:
<page-specification class="gov.irs.NewUserPage">
<component id="rulesForeach" type="Foreach">
<binding name="source" expression="rulesList"/>
<binding name="value" expression="rule"/>
</component>
<component id="ruleName" type="Insert">
<binding name="value" expression="rule.name"/>
</component>
</page-specification>
package ol5081;
import org.apache.tapestry.html.BasePage;
import java.util.*;
public class NewUser extends BasePage { // note - abstract removed
// this is called at the beginning of the Foreach
public ArrayList getRulesList() {
// your SQL code is called here i.e. ol5081.sqlj.Rules
}
// you really don't need this
// public ArrayList setRulesList(ArrayList value);
private Rule _rule = null ;
// use this in an Insert to display the results of each loop
public Rule getRule() {
return _rule ;
}
// the setter is called by the Foreach with each iteration
public void setRule(Rule rule) {
_rule = rule ;
}
}
Your NewUser.html needs to have a Foreach (not a @Foreach). @Foreach
creates a new instance and not the one spec'd in your .page file.
<SPAN jwcid="rulesForeach">
<SPAN jwcid="ruleName">Some Rule Name</SPAN><BR/>
</SPAN>
On Mon, Mar 29, 2004 at 12:29:20PM -0600, Trussell David N wrote:
> I'm fairly new to Java and even newer to Tapestry. I've searched the
> archives, read (part of) "Tapestry In Action" and played around with the
> example snippets in Tapestry->Doc->ComponentReference->Foreach. As much as I
> hate to admit it, I'm lost. Any help would be appreciated. Our story thus
> far:
>
> User enters identifier and is identified as a "new user" then
> cycle.activate("NewUser").
>
> NewUser.html will contain a "@Foreach" component for each row returned from
> the database. Just display at render time, nothing fancy, no tables, etc.
>
> NewUser.page contains:
>
> <page-specification class="ol5081.NewUser">
> <property-specification name="rulesList" type="java.util.ArrayList"
> persistent="yes" />
> <property-specification name="rule" type="ol5081.sqlj.Rules" />
> </page-specification>
>
> "Rules.java" contains SQLJ code (not sure that's relevant) that populates
> the ArrayList with rows returned from a query.
>
> NewUser.java contains:
>
> package ol5081;
>
> import org.apache.tapestry.html.BasePage;
> import java.util.*;
>
> public abstract class NewUser extends BasePage {
>
> public abstract ArrayList getRulesList();
>
> public abstract ArrayList setRulesList(ArrayList value);
> }
>
> I've tried quite a few different approaches with rather ugly results.
>
> Thank you all very much.
>
> Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org