You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Alec Leamas <le...@gmail.com> on 2008/04/01 23:26:51 UTC
Re: T5, newbie: Component parameter passing problems (#2)
My problem is not just with lists: If I use a custom type as parameter
instead of my List<MyMap> parameter I get the error: "Could not find a
coercion from type java.lang.String to type net.kln.yalt.report.Report"
where the Report is my custom type.
This is strange. I "have* been able to transfer the Report to a very
simple test component. Enclosing my "real" component, which doesn't seem
to accept parameter + the test component which accepts it.
So now I have five cases of parameter passing, with two components. Both
components are invoked from the same template, and uses the same getters
to provide the data. Results:
- List<String> : works OK in all cases.
- List<MyMap>: the parameter passed seems to be wrong, a single string
instead of a List<> when sent to class below.
- Report: Exception "Could not find coercion from String to Report"
when sent to class below.
- Report: works OK when sent to test component (4 lines).
- List<MyMap>: work ok when sent to test component
A little confused, I am. Part of this has been discussed earlier, no
visible solution though
(http://article.gmane.org/gmane.comp.java.tapestry.user/55319).
--alec
-------- Suspected class, does not accept parameters OK?
-----------------------
package net.kln.yalt.components;
import "stuff"
@IncludeStylesheet("context:css/yalt.css")
public class Layout
{
@Parameter( "false")
private String connectionUrl;
@Parameter
// private List<IRow> listSource;
private Report listSource;
@Parameter
private List<String> columns;
@Inject
private Messages messages;
@Inject
@Path( "context:icons/connect_no.png")
private Asset disconnectIcon;
@Inject
@Path( "context:icons/connect_established.png")
private Asset connectIcon;
@Inject
@Path( "context:icons/yalt.svg")
private Asset yaltIcon;
public Asset getYaltIcon() { return yaltIcon; }
public boolean isConnected()
{
return connectionUrl != null && !connectionUrl.equals( "false");
}
public Asset getDisconnectIcon() { return disconnectIcon; }
public Asset getConnectIcon() { return connectIcon; }
public boolean isListsVisible() { return listSource != null; }
public String getConnectionTooltip()
{
return messages.format( "connectionTooltip",
connectionUrl.replace( "%20", " "));
}
public List<String> getColumns() { return columns; }
// public List<IRow> getListSource() TODO revert
public Report getListSource() { return listSource; }
public String getOrvar() { return "" + listSource.size() } // Test
code!
}
--------------------------------- test component, seems to work
-----------------------------
public class ReportSize
{
@Parameter
private Report report;
@Parameter
private List<IRow> rows;
public Integer getReportSize() { return report.size(); }
public String getFirstMail()
{
return rows.get( 0).getColumnValue( "mail");
}
}
onathan Barker wrote:
>
> This is really sounding like something unrelated to Tapestry, and there
> isn't enough code presented to tell.
>
> Do you have proof that your code works outside of Tapestry? Why, and how,
> did you EXTEND TreeMap? Do you have a unit test to prove that your MyMap
> works?
>
> If you can present a non-Tapestry test that works, and corresponding
> Tapestry test that doesn't, then I think you'll find an answer quickly.
>
> Jonathan
>
>
>
>
>> -----Original Message-----
>> From: Alec Leamas [mailto:leamas.alec@gmail.com]
>> Sent: Tuesday, April 01, 2008 8:37 AM
>> To: Tapestry users
>> Subject: Re: T5, newbie: Component parameter passing problems
>>
>> public List<MyMap> getRows() {...}
>>
>> Davor Hrg wrote:
>>
>>> how is getRows declared in your page class ?
>>>
>>>
>>>
>>>
>>> On Tue, Apr 1, 2008 at 2:09 PM, Michael Kolmodin <Mi...@kolmodin.net>
>>> wrote:
>>>
>>>
>>>
>>>> OK, thanks...
>>>>
>>>> In my page, I have <t:myComponent columns="prop:columns"
>>>> rows="prop:rows"/>
>>>>
>>>> The columns argument, a List<String> is just fine.
>>>> The rows argument, a List<MyMap> is the problem.
>>>>
>>>> The page has a List<MyMap> getRows() which is verified.
>>>>
>>>> Looking in MyComponent.java, I have
>>>>
>>>> @Parameter
>>>> private List<MyMap> rows;
>>>>
>>>> @Parameter
>>>> private List<String> columns;
>>>>
>>>> public String getSomethingStrange()
>>>> {
>>>> return rows.get(0).get( "mail" );
>>>> }
>>>>
>>>> The latter getter fails. The debug info is from a breakpoint inside
>>>>
>> this
>>
>>>> method. The error I get is a classcast error "java.lang.String cannot
>>>>
>> be
>>
>>>> cast to ...MyMap" If I change the index to 1, there an error "Caused
>>>> by: Index: 1, Size: 1" i. e., index out of bounds.
>>>>
>>>> Davor Hrg wrote:
>>>>
>>>>
>>>>> Tapestry support for Java generics is very limited,
>>>>> you need a value encoder to make this work,
>>>>>
>>>>> also, add more details on who calls what... so more is known
>>>>> of the problem you are trying to solve.
>>>>>
>>>>>
>>>>> Davor Hrg
>>>>>
>>>>> On Tue, Apr 1, 2008 at 1:43 PM, Alec Leamas <le...@gmail.com>
>>>>>
>>>>>
>>>> wrote:
>>>>
>>>>
>>>>>> I have problems passing my own datatype(s) to my own component. The
>>>>>> component takes two parameters, one List<String> and one List<MyMap>.
>>>>>> MyMap is declared as MyMap extends TreeMap {...}.
>>>>>>
>>>>>> The first parameter, a list of strings arrives safely to my
>>>>>>
>> component.
>>
>>>>>> However, the other one, seems to be mixed up: when I try to access an
>>>>>> element in my List<MyMap>, it turns out that Tapestry (nothing else
>>>>>> involved) have filled this list with String items, not the expected
>>>>>> MyMap items. In the end, there is a class cast exception when trying
>>>>>>
>> to
>>
>>>>>> access the MyMap items as Maps.
>>>>>>
>>>>>> In the Eclipse debugger, it seems that the value of the List<MyMap>
>>>>>> instance variable is a single string holding what looks like the
>>>>>> serialized value of my List<MyMap> list. The start is
>>>>>> "[{key=value,key=value...
>>>>>>
>>>>>> I've tried to contribute coercions between MyMap<->Map, but this
>>>>>>
>> desn't
>>
>>>>>> seem to help (?).
>>>>>>
>>>>>> Basically, I'm stucked unless I write everything in several big pages
>>>>>> with duplicated code. Don't really want to do that. :-(
>>>>>>
>>>>>> Any hints out there?
>>>>>>
>>>>>> --alec
>>>>>>
>>>>>> PS Version: 5.0.11 DS
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5, newbie: Component parameter passing problems (#2)
Posted by Alec Leamas <le...@gmail.com>.
I actually got the same idea, just after pushing the send button. It's
quite a task, though, to carve this out. But it's certainly my job.
I'll make a try.
In the meanwhile: an observation. Looking at the breakpoint in
BugPage.getListsource () I can see the call stack. At the top is
Layout._$read_parameter_listSource() line: not available
InternalComponentResourcesImpl.readParameter(String, String) line: 248
InternalComponentResourcesImpl.readParameter(String, Class<T>) line: 233
To my understanding, this means that for some reason is indeed the
listSource parameters coerced to a String; this is what
readParameter(String, String) as all about?!
Stay tuned, I'll come be back w something compilable. Thanks for your time!
--alec
Josh Canfield wrote:
> Hey Alec,
>
> I was hoping for something a little more minimal, but still
> complete/compilable. :)
>
> I still can't reproduce the problem, but maybe @Persist on your report
> property is the culprit? Try it with out that. That's a shot in the
> dark though, so if that doesn't help I think I'll need something
> broken that I can actually run through a debugger to go any deeper.
>
> Josh
>
> On Wed, Apr 2, 2008 at 11:38 AM, Alec Leamas <le...@gmail.com> wrote:
>
>> Josh Canfield wrote:
>>
>>> Hey Alec,
>>>
>>> Looking at small excerpts from a large file leaves too much to the
>>> imagination. Can you create a minimal but complete page and component
>>> that reproduces the problem?
>>>
>>>
>>>
>> Yes, I should have done it long time ago, I know. Below is the complete
>> example, removing all old stuff trailing around. Here comes:
>>
>> - What's rendered (ascii)
>> - BugPage{.tml|.java}
>> - Layout{.tml,|java}
>> - ReportSize{.tml,.java}
>>
>> As you can see, the ReportSize component works whereas the Layout doesn't.
>> For the moment, I presume that the situation still is such that the problem
>> is about the listSource parameter, while the columns is fine.
>>
>> Debugger says same thing: the value returned from BugPage.getListsource() is
>> a List<IRow> w 500 items. The value stored as @Parameter listSource in
>> Layout is a SingletonList containing the serialized value of the 500 item
>> list. This is returned by getListSource() in Layout as-is.
>>
>> Note that I've cut away lot's of stuff from BugPage. Layout.java is as-is
>> (for now).
>>
>> --------------------------- rendered -------------------------------
>>
>> Orvar:1 // ${orvar}() in Layout reports size of singleton.
>>
>> YALT LDAP Report
>> Report for (mail=*), size: 500, aaliamb@u.washington.edu
>> // ReportSize works just fine.
>>
>> -------------------------- BugPage ---------------------------
>>
>>
>> <t:layout connectionUrl="${prop:connection.url}"
>> listSource="${prop:listSource}"
>> columns="${literal:cn,orvar}"
>>
>> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>> <head>
>> <title>Search</title>
>> </head>
>> <body class="tables">
>> <h1>YALT LDAP Report</h1>
>> Report for ${pattern}, size:
>> <t:reportsize report="prop:report" rows="prop:report.list" />
>> </body>
>>
>> </t:layout>
>>
>>
>> package net.kln.yalt.pages;
>>
>> import java.util.List;
>>
>> import javax.naming.NameNotFoundException;
>> import javax.naming.NamingException;
>>
>> import net.kln.yalt.aso.User;
>> import net.kln.yalt.data.ConnectionData;
>> import net.kln.yalt.report.AttributeList;
>> import net.kln.yalt.report.ILdapReportService;
>> import net.kln.yalt.report.IRow;
>> import net.kln.yalt.report.LdapReport;
>> import net.kln.yalt.report.LdapSchema;
>> import net.kln.yalt.report.Report;
>>
>> import org.apache.tapestry.annotations.Persist;
>> import org.apache.tapestry.ioc.annotations.Inject;
>> import org.slf4j.Logger;
>>
>> public class BugPage
>>
>> {
>> @Inject
>> private Logger log;
>>
>> @Inject
>> private ILdapReportService reportService;
>>
>> @Persist
>> private AttributeList attributeList;
>>
>> @Persist
>> private String pattern;
>>
>>
>> @Persist
>> private LdapReport report;
>>
>> @Persist
>> private User user;
>>
>> @Persist
>> private ConnectionData connection;
>>
>>
>> /** Initiate report to present a search result. */
>> public BugPage init( ConnectionData conn, User user, String pattern)
>>
>> {
>> try {
>> this.connection = conn;
>> this.user = user;
>> this.pattern = pattern;
>> report = reportService.getLdapReport( user);
>> attributeList = new AttributeList( user);
>> return this;
>> }
>> catch( Exception e) {
>> throw new RuntimeException( "Error creating report", e);
>> }
>> }
>>
>> public Object onActivate() throws NamingException
>> {
>> if( report.size() > 0 )
>> return null;
>> boolean searchOK = false;
>> try {
>> report.setReturnedAttributes( attributeList.getColumns());
>> report.patternSearch( pattern);
>> if( report.size() == 0)
>> throw new NameNotFoundException();
>>
>> else
>> searchOK = true;
>> }
>> catch( Exception e ) {}
>> finally {
>> if( searchOK)
>> {
>> log.debug( "Search done, matches: " + report.size());
>> LdapSchema schema = new LdapSchema( user.getDirContext());
>> if( schema.getAttributes() == null)
>> {
>> return null;
>> }
>> }
>> }
>> return null;
>>
>> }
>>
>> public Report getReport()
>> {
>> List<IRow> list = report.getList();
>> return report;
>> }
>>
>> public List<IRow> getListSource()
>> {
>> List<IRow> list = report.getList();
>> int size = list.size();
>> return list;
>> }
>>
>> public int getReportSize() { return report.size(); }
>>
>> public String getPattern() { return pattern; }
>>
>> public void setPattern(String pattern) { this.pattern = pattern; }
>>
>> public void setReport(LdapReport report) { this.report = report; }
>>
>> public User getUser() { return user; }
>>
>> public void setUser(User user) { this.user = user; }
>>
>> public ConnectionData getConnection() { return connection; }
>>
>> public void setConnection( ConnectionData connection)
>> {
>> this.connection = connection;
>> }
>> }
>> -------------------------- Layout -------------------------------------
>>
>> <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>> <head>
>> <title>YALT</title>
>> </head>
>> <body>
>> <div class="connection">
>> <t:if test="connected" else="block:notConnected">
>> <img src="${connectIcon}"
>> title="${prop:connectionTooltip}"/>
>> </t:if>
>> <t:block id="notConnected">
>> <img src="${disconnectIcon}"
>> title="${message:disconnectedTooltip}"/>
>> </t:block>
>> </div>
>>
>> <t:if test="listsVisible">
>> Orvar:${orvar}
>> </t:if>
>>
>> <t:pagelink page="start">
>> <img src="icons/yalt.gif" class="yaltIcon"/>
>> </t:pagelink>
>> <div class="flags"> <t:selectLocale/></div>
>>
>> <t:body/>
>>
>> </body>
>> </html>
>>
>> ---------------------------- Layout.java ----------------------------
>>
>> package net.kln.yalt.components;
>>
>> import java.util.List;
>>
>> import net.kln.yalt.report.IRow;
>>
>> import org.apache.tapestry.Asset;
>> import org.apache.tapestry.annotations.IncludeStylesheet;
>> import org.apache.tapestry.annotations.Parameter;
>> import org.apache.tapestry.annotations.Path;
>> import org.apache.tapestry.ioc.Messages;
>> import org.apache.tapestry.ioc.annotations.Inject;
>>
>>
>> @IncludeStylesheet("context:css/yalt.css")
>> public class Layout
>> {
>> @Parameter( "false")
>> private String connectionUrl;
>>
>> @Parameter
>> private List<IRow> listSource;
>>
>>
>> @Parameter
>> private List<String> columns;
>>
>> @Inject
>> private Messages messages;
>>
>> @Inject
>> @Path( "context:icons/connect_no.png")
>> private Asset disconnectIcon;
>>
>> @Inject
>> @Path( "context:icons/connect_established.png")
>> private Asset connectIcon;
>>
>> @Inject
>> @Path( "context:icons/yalt.svg")
>> private Asset yaltIcon;
>>
>> public Asset getYaltIcon()
>> {
>> return yaltIcon;
>> }
>>
>> public boolean isConnected()
>> {
>> return connectionUrl != null && !connectionUrl.equals( "false");
>> }
>>
>> public Asset getDisconnectIcon()
>> {
>> return disconnectIcon;
>> }
>>
>> public Asset getConnectIcon()
>> {
>> return connectIcon;
>> }
>>
>> public boolean isListsVisible()
>> {
>> return listSource != null;
>> }
>>
>> public String getConnectionTooltip()
>> {
>> return messages.format( "connectionTooltip",
>> connectionUrl.replace( "%20", " "));
>> }
>>
>> public List<String> getColumns()
>> {
>> return columns;
>> }
>>
>> public List<IRow> getListSource()
>> {
>>
>> return listSource;
>> }
>>
>> public String getOrvar()
>> {
>> return "" + listSource.size();
>> }
>> }
>> ----------------------------- ReportSize -------------------------
>>
>>
>> <t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>> ${reportSize}, ${firstMail}
>> </t:container>
>>
>>
>> package net.kln.yalt.components;
>>
>> import java.util.List;
>>
>> import net.kln.yalt.report.IRow;
>> import net.kln.yalt.report.Report;
>>
>> import org.apache.tapestry.annotations.Parameter;
>>
>>
>> public class ReportSize
>> {
>> @Parameter
>> private Report report;
>>
>> @Parameter
>> private List<IRow> rows;
>>
>> public Integer getReportSize() { return report.size(); }
>> public String getFirstMail()
>> {
>> return rows.get( 0).getColumnValue( "mail");
>> }
>> }
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5, newbie: Component parameter passing problems (#2)
Posted by Josh Canfield <jo...@thedailytube.com>.
Hey Alec,
I was hoping for something a little more minimal, but still
complete/compilable. :)
I still can't reproduce the problem, but maybe @Persist on your report
property is the culprit? Try it with out that. That's a shot in the
dark though, so if that doesn't help I think I'll need something
broken that I can actually run through a debugger to go any deeper.
Josh
On Wed, Apr 2, 2008 at 11:38 AM, Alec Leamas <le...@gmail.com> wrote:
> Josh Canfield wrote:
> > Hey Alec,
> >
> > Looking at small excerpts from a large file leaves too much to the
> > imagination. Can you create a minimal but complete page and component
> > that reproduces the problem?
> >
> >
>
> Yes, I should have done it long time ago, I know. Below is the complete
> example, removing all old stuff trailing around. Here comes:
>
> - What's rendered (ascii)
> - BugPage{.tml|.java}
> - Layout{.tml,|java}
> - ReportSize{.tml,.java}
>
> As you can see, the ReportSize component works whereas the Layout doesn't.
> For the moment, I presume that the situation still is such that the problem
> is about the listSource parameter, while the columns is fine.
>
> Debugger says same thing: the value returned from BugPage.getListsource() is
> a List<IRow> w 500 items. The value stored as @Parameter listSource in
> Layout is a SingletonList containing the serialized value of the 500 item
> list. This is returned by getListSource() in Layout as-is.
>
> Note that I've cut away lot's of stuff from BugPage. Layout.java is as-is
> (for now).
>
> --------------------------- rendered -------------------------------
>
> Orvar:1 // ${orvar}() in Layout reports size of singleton.
>
> YALT LDAP Report
> Report for (mail=*), size: 500, aaliamb@u.washington.edu
> // ReportSize works just fine.
>
> -------------------------- BugPage ---------------------------
>
>
> <t:layout connectionUrl="${prop:connection.url}"
> listSource="${prop:listSource}"
> columns="${literal:cn,orvar}"
>
> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
> <head>
> <title>Search</title>
> </head>
> <body class="tables">
> <h1>YALT LDAP Report</h1>
> Report for ${pattern}, size:
> <t:reportsize report="prop:report" rows="prop:report.list" />
> </body>
>
> </t:layout>
>
>
> package net.kln.yalt.pages;
>
> import java.util.List;
>
> import javax.naming.NameNotFoundException;
> import javax.naming.NamingException;
>
> import net.kln.yalt.aso.User;
> import net.kln.yalt.data.ConnectionData;
> import net.kln.yalt.report.AttributeList;
> import net.kln.yalt.report.ILdapReportService;
> import net.kln.yalt.report.IRow;
> import net.kln.yalt.report.LdapReport;
> import net.kln.yalt.report.LdapSchema;
> import net.kln.yalt.report.Report;
>
> import org.apache.tapestry.annotations.Persist;
> import org.apache.tapestry.ioc.annotations.Inject;
> import org.slf4j.Logger;
>
> public class BugPage
>
> {
> @Inject
> private Logger log;
>
> @Inject
> private ILdapReportService reportService;
>
> @Persist
> private AttributeList attributeList;
>
> @Persist
> private String pattern;
>
>
> @Persist
> private LdapReport report;
>
> @Persist
> private User user;
>
> @Persist
> private ConnectionData connection;
>
>
> /** Initiate report to present a search result. */
> public BugPage init( ConnectionData conn, User user, String pattern)
>
> {
> try {
> this.connection = conn;
> this.user = user;
> this.pattern = pattern;
> report = reportService.getLdapReport( user);
> attributeList = new AttributeList( user);
> return this;
> }
> catch( Exception e) {
> throw new RuntimeException( "Error creating report", e);
> }
> }
>
> public Object onActivate() throws NamingException
> {
> if( report.size() > 0 )
> return null;
> boolean searchOK = false;
> try {
> report.setReturnedAttributes( attributeList.getColumns());
> report.patternSearch( pattern);
> if( report.size() == 0)
> throw new NameNotFoundException();
>
> else
> searchOK = true;
> }
> catch( Exception e ) {}
> finally {
> if( searchOK)
> {
> log.debug( "Search done, matches: " + report.size());
> LdapSchema schema = new LdapSchema( user.getDirContext());
> if( schema.getAttributes() == null)
> {
> return null;
> }
> }
> }
> return null;
>
> }
>
> public Report getReport()
> {
> List<IRow> list = report.getList();
> return report;
> }
>
> public List<IRow> getListSource()
> {
> List<IRow> list = report.getList();
> int size = list.size();
> return list;
> }
>
> public int getReportSize() { return report.size(); }
>
> public String getPattern() { return pattern; }
>
> public void setPattern(String pattern) { this.pattern = pattern; }
>
> public void setReport(LdapReport report) { this.report = report; }
>
> public User getUser() { return user; }
>
> public void setUser(User user) { this.user = user; }
>
> public ConnectionData getConnection() { return connection; }
>
> public void setConnection( ConnectionData connection)
> {
> this.connection = connection;
> }
> }
> -------------------------- Layout -------------------------------------
>
> <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
> <head>
> <title>YALT</title>
> </head>
> <body>
> <div class="connection">
> <t:if test="connected" else="block:notConnected">
> <img src="${connectIcon}"
> title="${prop:connectionTooltip}"/>
> </t:if>
> <t:block id="notConnected">
> <img src="${disconnectIcon}"
> title="${message:disconnectedTooltip}"/>
> </t:block>
> </div>
>
> <t:if test="listsVisible">
> Orvar:${orvar}
> </t:if>
>
> <t:pagelink page="start">
> <img src="icons/yalt.gif" class="yaltIcon"/>
> </t:pagelink>
> <div class="flags"> <t:selectLocale/></div>
>
> <t:body/>
>
> </body>
> </html>
>
> ---------------------------- Layout.java ----------------------------
>
> package net.kln.yalt.components;
>
> import java.util.List;
>
> import net.kln.yalt.report.IRow;
>
> import org.apache.tapestry.Asset;
> import org.apache.tapestry.annotations.IncludeStylesheet;
> import org.apache.tapestry.annotations.Parameter;
> import org.apache.tapestry.annotations.Path;
> import org.apache.tapestry.ioc.Messages;
> import org.apache.tapestry.ioc.annotations.Inject;
>
>
> @IncludeStylesheet("context:css/yalt.css")
> public class Layout
> {
> @Parameter( "false")
> private String connectionUrl;
>
> @Parameter
> private List<IRow> listSource;
>
>
> @Parameter
> private List<String> columns;
>
> @Inject
> private Messages messages;
>
> @Inject
> @Path( "context:icons/connect_no.png")
> private Asset disconnectIcon;
>
> @Inject
> @Path( "context:icons/connect_established.png")
> private Asset connectIcon;
>
> @Inject
> @Path( "context:icons/yalt.svg")
> private Asset yaltIcon;
>
> public Asset getYaltIcon()
> {
> return yaltIcon;
> }
>
> public boolean isConnected()
> {
> return connectionUrl != null && !connectionUrl.equals( "false");
> }
>
> public Asset getDisconnectIcon()
> {
> return disconnectIcon;
> }
>
> public Asset getConnectIcon()
> {
> return connectIcon;
> }
>
> public boolean isListsVisible()
> {
> return listSource != null;
> }
>
> public String getConnectionTooltip()
> {
> return messages.format( "connectionTooltip",
> connectionUrl.replace( "%20", " "));
> }
>
> public List<String> getColumns()
> {
> return columns;
> }
>
> public List<IRow> getListSource()
> {
>
> return listSource;
> }
>
> public String getOrvar()
> {
> return "" + listSource.size();
> }
> }
> ----------------------------- ReportSize -------------------------
>
>
> <t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
> ${reportSize}, ${firstMail}
> </t:container>
>
>
> package net.kln.yalt.components;
>
> import java.util.List;
>
> import net.kln.yalt.report.IRow;
> import net.kln.yalt.report.Report;
>
> import org.apache.tapestry.annotations.Parameter;
>
>
> public class ReportSize
> {
> @Parameter
> private Report report;
>
> @Parameter
> private List<IRow> rows;
>
> public Integer getReportSize() { return report.size(); }
> public String getFirstMail()
> {
> return rows.get( 0).getColumnValue( "mail");
> }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5, newbie: Component parameter passing problems (ยค3)
Posted by Alec Leamas <le...@bredband.net>.
Hm... looking more into your example.... As I understand it, your
example and my ReportSize component are really similar and both do
indeed work demonstrating that *is* possible to pass the arguments. So
it is something with the Layout component...
Feeling dumb, need a better brain.
--alec
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5, newbie: Component parameter passing problems (#3)
Posted by Alec Leamas <le...@gmail.com>.
Hm... looking more on your example... Seems that yoyr example and my
ReportSize component are similar and both do indeed work. So it's
something with the Layout component...
--alec
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5, newbie: Component parameter passing problems (#2)
Posted by Alec Leamas <le...@gmail.com>.
Josh Canfield wrote:
> Hey Alec,
>
> Looking at small excerpts from a large file leaves too much to the
> imagination. Can you create a minimal but complete page and component
> that reproduces the problem?
>
Yes, I should have done it long time ago, I know. Below is the complete
example, removing all old stuff trailing around. Here comes:
- What's rendered (ascii)
- BugPage{.tml|.java}
- Layout{.tml,|java}
- ReportSize{.tml,.java}
As you can see, the ReportSize component works whereas the Layout
doesn't. For the moment, I presume that the situation still is such
that the problem is about the listSource parameter, while the columns is
fine.
Debugger says same thing: the value returned from
BugPage.getListsource() is a List<IRow> w 500 items. The value stored as
@Parameter listSource in Layout is a SingletonList containing the
serialized value of the 500 item list. This is returned by
getListSource() in Layout as-is.
Note that I've cut away lot's of stuff from BugPage. Layout.java is
as-is (for now).
--------------------------- rendered -------------------------------
Orvar:1 // ${orvar}() in Layout reports size of singleton.
YALT LDAP Report
Report for (mail=*), size: 500, aaliamb@u.washington.edu
// ReportSize works just fine.
-------------------------- BugPage ---------------------------
<t:layout connectionUrl="${prop:connection.url}"
listSource="${prop:listSource}"
columns="${literal:cn,orvar}"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<title>Search</title>
</head>
<body class="tables">
<h1>YALT LDAP Report</h1>
Report for ${pattern}, size:
<t:reportsize report="prop:report" rows="prop:report.list" />
</body>
</t:layout>
package net.kln.yalt.pages;
import java.util.List;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import net.kln.yalt.aso.User;
import net.kln.yalt.data.ConnectionData;
import net.kln.yalt.report.AttributeList;
import net.kln.yalt.report.ILdapReportService;
import net.kln.yalt.report.IRow;
import net.kln.yalt.report.LdapReport;
import net.kln.yalt.report.LdapSchema;
import net.kln.yalt.report.Report;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.ioc.annotations.Inject;
import org.slf4j.Logger;
public class BugPage
{
@Inject
private Logger log;
@Inject
private ILdapReportService reportService;
@Persist
private AttributeList attributeList;
@Persist
private String pattern;
@Persist
private LdapReport report;
@Persist
private User user;
@Persist
private ConnectionData connection;
/** Initiate report to present a search result. */
public BugPage init( ConnectionData conn, User user, String pattern)
{
try {
this.connection = conn;
this.user = user;
this.pattern = pattern;
report = reportService.getLdapReport( user);
attributeList = new AttributeList( user);
return this;
}
catch( Exception e) {
throw new RuntimeException( "Error creating report", e);
}
}
public Object onActivate() throws NamingException
{
if( report.size() > 0 )
return null;
boolean searchOK = false;
try {
report.setReturnedAttributes( attributeList.getColumns());
report.patternSearch( pattern);
if( report.size() == 0)
throw new NameNotFoundException();
else
searchOK = true;
}
catch( Exception e ) {}
finally {
if( searchOK)
{
log.debug( "Search done, matches: " + report.size());
LdapSchema schema = new LdapSchema( user.getDirContext());
if( schema.getAttributes() == null)
{
return null;
}
}
}
return null;
}
public Report getReport()
{
List<IRow> list = report.getList();
return report;
}
public List<IRow> getListSource()
{
List<IRow> list = report.getList();
int size = list.size();
return list;
}
public int getReportSize() { return report.size(); }
public String getPattern() { return pattern; }
public void setPattern(String pattern) { this.pattern = pattern; }
public void setReport(LdapReport report) { this.report = report; }
public User getUser() { return user; }
public void setUser(User user) { this.user = user; }
public ConnectionData getConnection() { return connection; }
public void setConnection( ConnectionData connection)
{
this.connection = connection;
}
}
-------------------------- Layout -------------------------------------
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<title>YALT</title>
</head>
<body>
<div class="connection">
<t:if test="connected" else="block:notConnected">
<img src="${connectIcon}"
title="${prop:connectionTooltip}"/>
</t:if>
<t:block id="notConnected">
<img src="${disconnectIcon}"
title="${message:disconnectedTooltip}"/>
</t:block>
</div>
<t:if test="listsVisible">
Orvar:${orvar}
</t:if>
<t:pagelink page="start">
<img src="icons/yalt.gif" class="yaltIcon"/>
</t:pagelink>
<div class="flags"> <t:selectLocale/></div>
<t:body/>
</body>
</html>
---------------------------- Layout.java ----------------------------
package net.kln.yalt.components;
import java.util.List;
import net.kln.yalt.report.IRow;
import org.apache.tapestry.Asset;
import org.apache.tapestry.annotations.IncludeStylesheet;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.annotations.Path;
import org.apache.tapestry.ioc.Messages;
import org.apache.tapestry.ioc.annotations.Inject;
@IncludeStylesheet("context:css/yalt.css")
public class Layout
{
@Parameter( "false")
private String connectionUrl;
@Parameter
private List<IRow> listSource;
@Parameter
private List<String> columns;
@Inject
private Messages messages;
@Inject
@Path( "context:icons/connect_no.png")
private Asset disconnectIcon;
@Inject
@Path( "context:icons/connect_established.png")
private Asset connectIcon;
@Inject
@Path( "context:icons/yalt.svg")
private Asset yaltIcon;
public Asset getYaltIcon()
{
return yaltIcon;
}
public boolean isConnected()
{
return connectionUrl != null && !connectionUrl.equals( "false");
}
public Asset getDisconnectIcon()
{
return disconnectIcon;
}
public Asset getConnectIcon()
{
return connectIcon;
}
public boolean isListsVisible()
{
return listSource != null;
}
public String getConnectionTooltip()
{
return messages.format( "connectionTooltip",
connectionUrl.replace( "%20", " "));
}
public List<String> getColumns()
{
return columns;
}
public List<IRow> getListSource()
{
return listSource;
}
public String getOrvar()
{
return "" + listSource.size();
}
}
----------------------------- ReportSize -------------------------
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
${reportSize}, ${firstMail}
</t:container>
package net.kln.yalt.components;
import java.util.List;
import net.kln.yalt.report.IRow;
import net.kln.yalt.report.Report;
import org.apache.tapestry.annotations.Parameter;
public class ReportSize
{
@Parameter
private Report report;
@Parameter
private List<IRow> rows;
public Integer getReportSize() { return report.size(); }
public String getFirstMail()
{
return rows.get( 0).getColumnValue( "mail");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5, newbie: Component parameter passing problems (#2)
Posted by Josh Canfield <jo...@thedailytube.com>.
Hey Alec,
Looking at small excerpts from a large file leaves too much to the
imagination. Can you create a minimal but complete page and component
that reproduces the problem?
It feels like there is a bad return type or something on one of the
methods in the chain, so having a complete non-working example would
make it easier to debug.
Here is my working example, I tried to make it close to what you are doing.
****************** myapp.pages.Start.java:
public class Start
{
public List<String> getStrings() {
List<String> strings = new ArrayList<String>();
strings.add("Hello");
strings.add("Goodbye");
return strings;
}
@SuppressWarnings("unchecked")
public List<MyMap> getMaps() {
List<MyMap> maps = new ArrayList<MyMap>();
MyMap map = new MyMap();
map.put(0, "Zero");
map.put(1, "One");
maps.add(map);
map = new MyMap();
map.put("horse", "buck");
map.put("goose", "egg");
maps.add(map);
return maps;
}
public String getSomethingStrange() {
return (String)getMaps().get(0).get(1);
}
}
****************** myapp.pages.Start.tml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<t:layout t:strings="prop:strings" t:maps="prop:maps"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
This is the body
</t:layout>
******************** myapp.components.Layout.java
public class Layout {
@Parameter
private List<String> _strings;
@Parameter
private List<MyMap> _maps;
public String getSomethingStrange() {
return (String)_maps.get(0).get(1);
}
public List<String> getStrings() {
return _strings;
}
public void setStrings(List<String> strings) {
_strings = strings;
}
public List<MyMap> getMaps() {
return _maps;
}
public void setMaps(List<MyMap> maps) {
_maps = maps;
}
}
******************** myapp.components.Layout.tml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<body>
<p>Strange: ${somethingStrange}</p>
<div style="border: thin red solid;"><t:body /></div>
</body>
</html>
******************** MyMap.java (for completeness...)
package joshcan.test;
import java.util.TreeMap;
@SuppressWarnings("unchecked")
public class MyMap extends TreeMap {
@Override
public Object get(Object key) {
Object o = super.get(key);
return "my" + o.toString();
}
}
************* Rendered output (hand formatted for readability)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="/assets/tapestry/default.css" rel="stylesheet" type="text/css">
</head>
<body>
<p>Strange: myOne</p>
<div style="border: thin red solid;">This is the body</div>
</body>
</html>
Hope that helps,
Josh
--
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5, newbie: Component parameter passing problems (#2)
Posted by Alec Leamas <le...@gmail.com>.
More and more mysterious... The relevant getters in the page is
getListSource() and getReport(), enclosing excerpts from page below.
The problems seems to be related to getListSource(). The call chain as
I understand it:
- ${orvar} in layout.tmpl is fetching data data from Layout.getOrvar();
- Layout.getOrvar() gets data from Layout.@Parameter listSource.
- Layout.@Parameter listSource gets data from reportPage.getListSource();
Breakpoint in ReportPage.getListSource() shows that the returned list is
perfectly OK (size 500).
Breakpoint in Layout.getOrvar reveals that listSource is a
Collections$SingletonList. (?!)
The value from Layout.getOrvar() (sorry for Swedish foobar name) is 1 i.
e., the size of the Singleton list.
So: somewhere on the way from the page getter getListource() to the
component parameter listSource the value is converted from a List<IRow>
to a SingletonList holding the serialized value of original list. For
me, it looks like the coercion is involved, but I just can't understand
why. I really wish I understood more...
Cheers,
--alec
Page code:
...
@Inject
private Logger log;
@Inject
private Messages messages;
@Inject
private ILdapReportService reportService;
...
@Persist
private LdapReport report;
...
@Persist
private User user;
...
/** Initiate report to present a search result. */
public ReportPage init( ConnectionData conn, User user, String pattern)
{
try
{
this.connection = conn;
this.user = user;
this.pattern = pattern;
if( pageSize == null)
pageSize = 25; // DEFAULT_PAGESIZE;
pageStart = 0;
report = reportService.getLdapReport( user);
attributeList = new AttributeList( user);
return this;
}
catch( Exception e)
{
throw new RuntimeException( "Error creating report", e);
}
}
...
public Report getReport()
{
List<IRow> list = report.getList(); //TODO Revert
return report;
}
public List<IRow> getListSource()
{
List<IRow> list = report.getList(); //TODO Revert
int size = list.size();
return list;
}
----------------------------------------------- Page template
(excerpt.)-----------------
<t:layout connectionUrl="${prop:connection.url}"
listSource="${prop:listSource}"
columns="${prop:attributeList.columns}"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<title>Search</title>
</head>
<body class="tables">
<h1>YALT LDAP Report</h1>
Report for ${pattern}, size: <t:reportsize
report="prop:report" rows="prop:report.list" />
.......
---------------------------------------- Layout template (excerpt,
displays "Orvar: 1" -------------------------
<t:if test="listsVisible">
Orvar:${orvar}
</t:if>
------------------------------------ ReportSize test template (OK)
--------------------------------------
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
${reportSize}, ${firstMail}
</t:container>
--------------------------------------------------------------------------------------------------
Jonathan Barker wrote:
> Sorry for the delay - meetings all day.
>
> Josh Canfield made a suggestion regarding setting a breakpoint. I would
> echo that, and make sure that you try the same code in the page class.
>
> You've shared the component code. Can you share the relevant page code?
> (Declaration, initialization, getters and setters...)
>
> Jonathan
>
>
>> -----Original Message-----
>> From: Alec Leamas [mailto:leamas.alec@gmail.com]
>> Sent: Tuesday, April 01, 2008 5:27 PM
>> To: Tapestry users
>> Subject: Re: T5, newbie: Component parameter passing problems (#2)
>>
>> My problem is not just with lists: If I use a custom type as parameter
>> instead of my List<MyMap> parameter I get the error: "Could not find a
>> coercion from type java.lang.String to type net.kln.yalt.report.Report"
>> where the Report is my custom type.
>>
>> This is strange. I "have* been able to transfer the Report to a very
>> simple test component. Enclosing my "real" component, which doesn't seem
>> to accept parameter + the test component which accepts it.
>>
>> So now I have five cases of parameter passing, with two components. Both
>> components are invoked from the same template, and uses the same getters
>> to provide the data. Results:
>>
>> - List<String> : works OK in all cases.
>> - List<MyMap>: the parameter passed seems to be wrong, a single string
>> instead of a List<> when sent to class below.
>> - Report: Exception "Could not find coercion from String to Report"
>> when sent to class below.
>> - Report: works OK when sent to test component (4 lines).
>> - List<MyMap>: work ok when sent to test component
>>
>> A little confused, I am. Part of this has been discussed earlier, no
>> visible solution though
>> (http://article.gmane.org/gmane.comp.java.tapestry.user/55319).
>>
>> --alec
>>
>>
>> -------- Suspected class, does not accept parameters OK?
>> -----------------------
>> package net.kln.yalt.components;
>> import "stuff"
>> @IncludeStylesheet("context:css/yalt.css")
>> public class Layout
>> {
>> @Parameter( "false")
>> private String connectionUrl;
>>
>> @Parameter
>> // private List<IRow> listSource;
>> private Report listSource;
>>
>> @Parameter
>> private List<String> columns;
>>
>> @Inject
>> private Messages messages;
>>
>> @Inject
>> @Path( "context:icons/connect_no.png")
>> private Asset disconnectIcon;
>>
>> @Inject
>> @Path( "context:icons/connect_established.png")
>> private Asset connectIcon;
>>
>> @Inject
>> @Path( "context:icons/yalt.svg")
>> private Asset yaltIcon;
>>
>> public Asset getYaltIcon() { return yaltIcon; }
>>
>> public boolean isConnected()
>> {
>> return connectionUrl != null && !connectionUrl.equals( "false");
>> }
>>
>> public Asset getDisconnectIcon() { return disconnectIcon; }
>>
>> public Asset getConnectIcon() { return connectIcon; }
>>
>> public boolean isListsVisible() { return listSource != null; }
>>
>> public String getConnectionTooltip()
>> {
>> return messages.format( "connectionTooltip",
>> connectionUrl.replace( "%20", " "));
>> }
>>
>> public List<String> getColumns() { return columns; }
>>
>> // public List<IRow> getListSource() TODO revert
>> public Report getListSource() { return listSource; }
>> public String getOrvar() { return "" + listSource.size() } // Test
>> code!
>> }
>>
>> --------------------------------- test component, seems to work
>> -----------------------------
>> public class ReportSize
>> {
>> @Parameter
>> private Report report;
>>
>> @Parameter
>> private List<IRow> rows;
>>
>> public Integer getReportSize() { return report.size(); }
>> public String getFirstMail()
>> {
>> return rows.get( 0).getColumnValue( "mail");
>> }
>> }
>>
>>
>> onathan Barker wrote:
>>
>>> This is really sounding like something unrelated to Tapestry, and there
>>> isn't enough code presented to tell.
>>>
>>> Do you have proof that your code works outside of Tapestry? Why, and
>>>
>> how,
>>
>>> did you EXTEND TreeMap? Do you have a unit test to prove that your
>>>
>> MyMap
>>
>>> works?
>>>
>>> If you can present a non-Tapestry test that works, and corresponding
>>> Tapestry test that doesn't, then I think you'll find an answer quickly.
>>>
>>> Jonathan
>>>
>>>
>>>
>>>
>>>
>>>> -----Original Message-----
>>>> From: Alec Leamas [mailto:leamas.alec@gmail.com]
>>>> Sent: Tuesday, April 01, 2008 8:37 AM
>>>> To: Tapestry users
>>>> Subject: Re: T5, newbie: Component parameter passing problems
>>>>
>>>> public List<MyMap> getRows() {...}
>>>>
>>>> Davor Hrg wrote:
>>>>
>>>>
>>>>> how is getRows declared in your page class ?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Apr 1, 2008 at 2:09 PM, Michael Kolmodin
>>>>>
>> <Mi...@kolmodin.net>
>>
>>>>> wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> OK, thanks...
>>>>>>
>>>>>> In my page, I have <t:myComponent columns="prop:columns"
>>>>>> rows="prop:rows"/>
>>>>>>
>>>>>> The columns argument, a List<String> is just fine.
>>>>>> The rows argument, a List<MyMap> is the problem.
>>>>>>
>>>>>> The page has a List<MyMap> getRows() which is verified.
>>>>>>
>>>>>> Looking in MyComponent.java, I have
>>>>>>
>>>>>> @Parameter
>>>>>> private List<MyMap> rows;
>>>>>>
>>>>>> @Parameter
>>>>>> private List<String> columns;
>>>>>>
>>>>>> public String getSomethingStrange()
>>>>>> {
>>>>>> return rows.get(0).get( "mail" );
>>>>>> }
>>>>>>
>>>>>> The latter getter fails. The debug info is from a breakpoint inside
>>>>>>
>>>>>>
>>>> this
>>>>
>>>>
>>>>>> method. The error I get is a classcast error "java.lang.String cannot
>>>>>>
>>>>>>
>>>> be
>>>>
>>>>
>>>>>> cast to ...MyMap" If I change the index to 1, there an error "Caused
>>>>>> by: Index: 1, Size: 1" i. e., index out of bounds.
>>>>>>
>>>>>> Davor Hrg wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>> Tapestry support for Java generics is very limited,
>>>>>>> you need a value encoder to make this work,
>>>>>>>
>>>>>>> also, add more details on who calls what... so more is known
>>>>>>> of the problem you are trying to solve.
>>>>>>>
>>>>>>>
>>>>>>> Davor Hrg
>>>>>>>
>>>>>>> On Tue, Apr 1, 2008 at 1:43 PM, Alec Leamas <le...@gmail.com>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>> I have problems passing my own datatype(s) to my own component. The
>>>>>>>> component takes two parameters, one List<String> and one
>>>>>>>>
>> List<MyMap>.
>>
>>>>>>>> MyMap is declared as MyMap extends TreeMap {...}.
>>>>>>>>
>>>>>>>> The first parameter, a list of strings arrives safely to my
>>>>>>>>
>>>>>>>>
>>>> component.
>>>>
>>>>
>>>>>>>> However, the other one, seems to be mixed up: when I try to access
>>>>>>>>
>> an
>>
>>>>>>>> element in my List<MyMap>, it turns out that Tapestry (nothing else
>>>>>>>> involved) have filled this list with String items, not the
>>>>>>>>
>> expected
>>
>>>>>>>> MyMap items. In the end, there is a class cast exception when
>>>>>>>>
>> trying
>>
>>>> to
>>>>
>>>>
>>>>>>>> access the MyMap items as Maps.
>>>>>>>>
>>>>>>>> In the Eclipse debugger, it seems that the value of the List<MyMap>
>>>>>>>> instance variable is a single string holding what looks like the
>>>>>>>> serialized value of my List<MyMap> list. The start is
>>>>>>>> "[{key=value,key=value...
>>>>>>>>
>>>>>>>> I've tried to contribute coercions between MyMap<->Map, but this
>>>>>>>>
>>>>>>>>
>>>> desn't
>>>>
>>>>
>>>>>>>> seem to help (?).
>>>>>>>>
>>>>>>>> Basically, I'm stucked unless I write everything in several big
>>>>>>>>
>> pages
>>
>>>>>>>> with duplicated code. Don't really want to do that. :-(
>>>>>>>>
>>>>>>>> Any hints out there?
>>>>>>>>
>>>>>>>> --alec
>>>>>>>>
>>>>>>>> PS Version: 5.0.11 DS
>>>>>>>>
>>>>>>>> -------------------------------------------------------------------
>>>>>>>>
>> --
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5, newbie: Component parameter passing problems (#2)
Posted by Alec Leamas <le...@gmail.com>.
"Sorry for the delay". I'm amazed over the help I get, and you
shouldn't really have to say "Sorry". But I need to say "Thanks"!
I read Josh's answer as "No, Tapestry should really treat all
parameters be it List<String>, List<MyMap> or MyObject the same". (?)
I'm on CET, and will come back into this later, I also have some other
things to do for the moment. I feel much more confident now after the
explanation how the parameter value is accessed from the page source.
--alec
PS: I have really no problems sharing anything. What's limiting me it's
just a a wish not to take anybodys time with large chunks of irrelevant
code. DS
Jonathan Barker wrote:
> Sorry for the delay - meetings all day.
>
> Josh Canfield made a suggestion regarding setting a breakpoint. I would
> echo that, and make sure that you try the same code in the page class.
>
> You've shared the component code. Can you share the relevant page code?
> (Declaration, initialization, getters and setters...)
>
> Jonathan
>
>
>> -----Original Message-----
>> From: Alec Leamas [mailto:leamas.alec@gmail.com]
>> Sent: Tuesday, April 01, 2008 5:27 PM
>> To: Tapestry users
>> Subject: Re: T5, newbie: Component parameter passing problems (#2)
>>
>> My problem is not just with lists: If I use a custom type as parameter
>> instead of my List<MyMap> parameter I get the error: "Could not find a
>> coercion from type java.lang.String to type net.kln.yalt.report.Report"
>> where the Report is my custom type.
>>
>> This is strange. I "have* been able to transfer the Report to a very
>> simple test component. Enclosing my "real" component, which doesn't seem
>> to accept parameter + the test component which accepts it.
>>
>> So now I have five cases of parameter passing, with two components. Both
>> components are invoked from the same template, and uses the same getters
>> to provide the data. Results:
>>
>> - List<String> : works OK in all cases.
>> - List<MyMap>: the parameter passed seems to be wrong, a single string
>> instead of a List<> when sent to class below.
>> - Report: Exception "Could not find coercion from String to Report"
>> when sent to class below.
>> - Report: works OK when sent to test component (4 lines).
>> - List<MyMap>: work ok when sent to test component
>>
>> A little confused, I am. Part of this has been discussed earlier, no
>> visible solution though
>> (http://article.gmane.org/gmane.comp.java.tapestry.user/55319).
>>
>> --alec
>>
>>
>> -------- Suspected class, does not accept parameters OK?
>> -----------------------
>> package net.kln.yalt.components;
>> import "stuff"
>> @IncludeStylesheet("context:css/yalt.css")
>> public class Layout
>> {
>> @Parameter( "false")
>> private String connectionUrl;
>>
>> @Parameter
>> // private List<IRow> listSource;
>> private Report listSource;
>>
>> @Parameter
>> private List<String> columns;
>>
>> @Inject
>> private Messages messages;
>>
>> @Inject
>> @Path( "context:icons/connect_no.png")
>> private Asset disconnectIcon;
>>
>> @Inject
>> @Path( "context:icons/connect_established.png")
>> private Asset connectIcon;
>>
>> @Inject
>> @Path( "context:icons/yalt.svg")
>> private Asset yaltIcon;
>>
>> public Asset getYaltIcon() { return yaltIcon; }
>>
>> public boolean isConnected()
>> {
>> return connectionUrl != null && !connectionUrl.equals( "false");
>> }
>>
>> public Asset getDisconnectIcon() { return disconnectIcon; }
>>
>> public Asset getConnectIcon() { return connectIcon; }
>>
>> public boolean isListsVisible() { return listSource != null; }
>>
>> public String getConnectionTooltip()
>> {
>> return messages.format( "connectionTooltip",
>> connectionUrl.replace( "%20", " "));
>> }
>>
>> public List<String> getColumns() { return columns; }
>>
>> // public List<IRow> getListSource() TODO revert
>> public Report getListSource() { return listSource; }
>> public String getOrvar() { return "" + listSource.size() } // Test
>> code!
>> }
>>
>> --------------------------------- test component, seems to work
>> -----------------------------
>> public class ReportSize
>> {
>> @Parameter
>> private Report report;
>>
>> @Parameter
>> private List<IRow> rows;
>>
>> public Integer getReportSize() { return report.size(); }
>> public String getFirstMail()
>> {
>> return rows.get( 0).getColumnValue( "mail");
>> }
>> }
>>
>>
>> onathan Barker wrote:
>>
>>> This is really sounding like something unrelated to Tapestry, and there
>>> isn't enough code presented to tell.
>>>
>>> Do you have proof that your code works outside of Tapestry? Why, and
>>>
>> how,
>>
>>> did you EXTEND TreeMap? Do you have a unit test to prove that your
>>>
>> MyMap
>>
>>> works?
>>>
>>> If you can present a non-Tapestry test that works, and corresponding
>>> Tapestry test that doesn't, then I think you'll find an answer quickly.
>>>
>>> Jonathan
>>>
>>>
>>>
>>>
>>>
>>>> -----Original Message-----
>>>> From: Alec Leamas [mailto:leamas.alec@gmail.com]
>>>> Sent: Tuesday, April 01, 2008 8:37 AM
>>>> To: Tapestry users
>>>> Subject: Re: T5, newbie: Component parameter passing problems
>>>>
>>>> public List<MyMap> getRows() {...}
>>>>
>>>> Davor Hrg wrote:
>>>>
>>>>
>>>>> how is getRows declared in your page class ?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Apr 1, 2008 at 2:09 PM, Michael Kolmodin
>>>>>
>> <Mi...@kolmodin.net>
>>
>>>>> wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> OK, thanks...
>>>>>>
>>>>>> In my page, I have <t:myComponent columns="prop:columns"
>>>>>> rows="prop:rows"/>
>>>>>>
>>>>>> The columns argument, a List<String> is just fine.
>>>>>> The rows argument, a List<MyMap> is the problem.
>>>>>>
>>>>>> The page has a List<MyMap> getRows() which is verified.
>>>>>>
>>>>>> Looking in MyComponent.java, I have
>>>>>>
>>>>>> @Parameter
>>>>>> private List<MyMap> rows;
>>>>>>
>>>>>> @Parameter
>>>>>> private List<String> columns;
>>>>>>
>>>>>> public String getSomethingStrange()
>>>>>> {
>>>>>> return rows.get(0).get( "mail" );
>>>>>> }
>>>>>>
>>>>>> The latter getter fails. The debug info is from a breakpoint inside
>>>>>>
>>>>>>
>>>> this
>>>>
>>>>
>>>>>> method. The error I get is a classcast error "java.lang.String cannot
>>>>>>
>>>>>>
>>>> be
>>>>
>>>>
>>>>>> cast to ...MyMap" If I change the index to 1, there an error "Caused
>>>>>> by: Index: 1, Size: 1" i. e., index out of bounds.
>>>>>>
>>>>>> Davor Hrg wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>> Tapestry support for Java generics is very limited,
>>>>>>> you need a value encoder to make this work,
>>>>>>>
>>>>>>> also, add more details on who calls what... so more is known
>>>>>>> of the problem you are trying to solve.
>>>>>>>
>>>>>>>
>>>>>>> Davor Hrg
>>>>>>>
>>>>>>> On Tue, Apr 1, 2008 at 1:43 PM, Alec Leamas <le...@gmail.com>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>> I have problems passing my own datatype(s) to my own component. The
>>>>>>>> component takes two parameters, one List<String> and one
>>>>>>>>
>> List<MyMap>.
>>
>>>>>>>> MyMap is declared as MyMap extends TreeMap {...}.
>>>>>>>>
>>>>>>>> The first parameter, a list of strings arrives safely to my
>>>>>>>>
>>>>>>>>
>>>> component.
>>>>
>>>>
>>>>>>>> However, the other one, seems to be mixed up: when I try to access
>>>>>>>>
>> an
>>
>>>>>>>> element in my List<MyMap>, it turns out that Tapestry (nothing else
>>>>>>>> involved) have filled this list with String items, not the
>>>>>>>>
>> expected
>>
>>>>>>>> MyMap items. In the end, there is a class cast exception when
>>>>>>>>
>> trying
>>
>>>> to
>>>>
>>>>
>>>>>>>> access the MyMap items as Maps.
>>>>>>>>
>>>>>>>> In the Eclipse debugger, it seems that the value of the List<MyMap>
>>>>>>>> instance variable is a single string holding what looks like the
>>>>>>>> serialized value of my List<MyMap> list. The start is
>>>>>>>> "[{key=value,key=value...
>>>>>>>>
>>>>>>>> I've tried to contribute coercions between MyMap<->Map, but this
>>>>>>>>
>>>>>>>>
>>>> desn't
>>>>
>>>>
>>>>>>>> seem to help (?).
>>>>>>>>
>>>>>>>> Basically, I'm stucked unless I write everything in several big
>>>>>>>>
>> pages
>>
>>>>>>>> with duplicated code. Don't really want to do that. :-(
>>>>>>>>
>>>>>>>> Any hints out there?
>>>>>>>>
>>>>>>>> --alec
>>>>>>>>
>>>>>>>> PS Version: 5.0.11 DS
>>>>>>>>
>>>>>>>> -------------------------------------------------------------------
>>>>>>>>
>> --
>>
>>>>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
RE: T5, newbie: Component parameter passing problems (#2)
Posted by Jonathan Barker <jo...@gmail.com>.
Sorry for the delay - meetings all day.
Josh Canfield made a suggestion regarding setting a breakpoint. I would
echo that, and make sure that you try the same code in the page class.
You've shared the component code. Can you share the relevant page code?
(Declaration, initialization, getters and setters...)
Jonathan
> -----Original Message-----
> From: Alec Leamas [mailto:leamas.alec@gmail.com]
> Sent: Tuesday, April 01, 2008 5:27 PM
> To: Tapestry users
> Subject: Re: T5, newbie: Component parameter passing problems (#2)
>
> My problem is not just with lists: If I use a custom type as parameter
> instead of my List<MyMap> parameter I get the error: "Could not find a
> coercion from type java.lang.String to type net.kln.yalt.report.Report"
> where the Report is my custom type.
>
> This is strange. I "have* been able to transfer the Report to a very
> simple test component. Enclosing my "real" component, which doesn't seem
> to accept parameter + the test component which accepts it.
>
> So now I have five cases of parameter passing, with two components. Both
> components are invoked from the same template, and uses the same getters
> to provide the data. Results:
>
> - List<String> : works OK in all cases.
> - List<MyMap>: the parameter passed seems to be wrong, a single string
> instead of a List<> when sent to class below.
> - Report: Exception "Could not find coercion from String to Report"
> when sent to class below.
> - Report: works OK when sent to test component (4 lines).
> - List<MyMap>: work ok when sent to test component
>
> A little confused, I am. Part of this has been discussed earlier, no
> visible solution though
> (http://article.gmane.org/gmane.comp.java.tapestry.user/55319).
>
> --alec
>
>
> -------- Suspected class, does not accept parameters OK?
> -----------------------
> package net.kln.yalt.components;
> import "stuff"
> @IncludeStylesheet("context:css/yalt.css")
> public class Layout
> {
> @Parameter( "false")
> private String connectionUrl;
>
> @Parameter
> // private List<IRow> listSource;
> private Report listSource;
>
> @Parameter
> private List<String> columns;
>
> @Inject
> private Messages messages;
>
> @Inject
> @Path( "context:icons/connect_no.png")
> private Asset disconnectIcon;
>
> @Inject
> @Path( "context:icons/connect_established.png")
> private Asset connectIcon;
>
> @Inject
> @Path( "context:icons/yalt.svg")
> private Asset yaltIcon;
>
> public Asset getYaltIcon() { return yaltIcon; }
>
> public boolean isConnected()
> {
> return connectionUrl != null && !connectionUrl.equals( "false");
> }
>
> public Asset getDisconnectIcon() { return disconnectIcon; }
>
> public Asset getConnectIcon() { return connectIcon; }
>
> public boolean isListsVisible() { return listSource != null; }
>
> public String getConnectionTooltip()
> {
> return messages.format( "connectionTooltip",
> connectionUrl.replace( "%20", " "));
> }
>
> public List<String> getColumns() { return columns; }
>
> // public List<IRow> getListSource() TODO revert
> public Report getListSource() { return listSource; }
> public String getOrvar() { return "" + listSource.size() } // Test
> code!
> }
>
> --------------------------------- test component, seems to work
> -----------------------------
> public class ReportSize
> {
> @Parameter
> private Report report;
>
> @Parameter
> private List<IRow> rows;
>
> public Integer getReportSize() { return report.size(); }
> public String getFirstMail()
> {
> return rows.get( 0).getColumnValue( "mail");
> }
> }
>
>
> onathan Barker wrote:
> >
> > This is really sounding like something unrelated to Tapestry, and there
> > isn't enough code presented to tell.
> >
> > Do you have proof that your code works outside of Tapestry? Why, and
> how,
> > did you EXTEND TreeMap? Do you have a unit test to prove that your
> MyMap
> > works?
> >
> > If you can present a non-Tapestry test that works, and corresponding
> > Tapestry test that doesn't, then I think you'll find an answer quickly.
> >
> > Jonathan
> >
> >
> >
> >
> >> -----Original Message-----
> >> From: Alec Leamas [mailto:leamas.alec@gmail.com]
> >> Sent: Tuesday, April 01, 2008 8:37 AM
> >> To: Tapestry users
> >> Subject: Re: T5, newbie: Component parameter passing problems
> >>
> >> public List<MyMap> getRows() {...}
> >>
> >> Davor Hrg wrote:
> >>
> >>> how is getRows declared in your page class ?
> >>>
> >>>
> >>>
> >>>
> >>> On Tue, Apr 1, 2008 at 2:09 PM, Michael Kolmodin
> <Mi...@kolmodin.net>
> >>> wrote:
> >>>
> >>>
> >>>
> >>>> OK, thanks...
> >>>>
> >>>> In my page, I have <t:myComponent columns="prop:columns"
> >>>> rows="prop:rows"/>
> >>>>
> >>>> The columns argument, a List<String> is just fine.
> >>>> The rows argument, a List<MyMap> is the problem.
> >>>>
> >>>> The page has a List<MyMap> getRows() which is verified.
> >>>>
> >>>> Looking in MyComponent.java, I have
> >>>>
> >>>> @Parameter
> >>>> private List<MyMap> rows;
> >>>>
> >>>> @Parameter
> >>>> private List<String> columns;
> >>>>
> >>>> public String getSomethingStrange()
> >>>> {
> >>>> return rows.get(0).get( "mail" );
> >>>> }
> >>>>
> >>>> The latter getter fails. The debug info is from a breakpoint inside
> >>>>
> >> this
> >>
> >>>> method. The error I get is a classcast error "java.lang.String cannot
> >>>>
> >> be
> >>
> >>>> cast to ...MyMap" If I change the index to 1, there an error "Caused
> >>>> by: Index: 1, Size: 1" i. e., index out of bounds.
> >>>>
> >>>> Davor Hrg wrote:
> >>>>
> >>>>
> >>>>> Tapestry support for Java generics is very limited,
> >>>>> you need a value encoder to make this work,
> >>>>>
> >>>>> also, add more details on who calls what... so more is known
> >>>>> of the problem you are trying to solve.
> >>>>>
> >>>>>
> >>>>> Davor Hrg
> >>>>>
> >>>>> On Tue, Apr 1, 2008 at 1:43 PM, Alec Leamas <le...@gmail.com>
> >>>>>
> >>>>>
> >>>> wrote:
> >>>>
> >>>>
> >>>>>> I have problems passing my own datatype(s) to my own component. The
> >>>>>> component takes two parameters, one List<String> and one
> List<MyMap>.
> >>>>>> MyMap is declared as MyMap extends TreeMap {...}.
> >>>>>>
> >>>>>> The first parameter, a list of strings arrives safely to my
> >>>>>>
> >> component.
> >>
> >>>>>> However, the other one, seems to be mixed up: when I try to access
> an
> >>>>>> element in my List<MyMap>, it turns out that Tapestry (nothing else
> >>>>>> involved) have filled this list with String items, not the
> expected
> >>>>>> MyMap items. In the end, there is a class cast exception when
> trying
> >>>>>>
> >> to
> >>
> >>>>>> access the MyMap items as Maps.
> >>>>>>
> >>>>>> In the Eclipse debugger, it seems that the value of the List<MyMap>
> >>>>>> instance variable is a single string holding what looks like the
> >>>>>> serialized value of my List<MyMap> list. The start is
> >>>>>> "[{key=value,key=value...
> >>>>>>
> >>>>>> I've tried to contribute coercions between MyMap<->Map, but this
> >>>>>>
> >> desn't
> >>
> >>>>>> seem to help (?).
> >>>>>>
> >>>>>> Basically, I'm stucked unless I write everything in several big
> pages
> >>>>>> with duplicated code. Don't really want to do that. :-(
> >>>>>>
> >>>>>> Any hints out there?
> >>>>>>
> >>>>>> --alec
> >>>>>>
> >>>>>> PS Version: 5.0.11 DS
> >>>>>>
> >>>>>> -------------------------------------------------------------------
> --
> >>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org