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 [EMAIL PROTECTED] listSource.
- [EMAIL PROTECTED] 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:[EMAIL PROTECTED]
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:[EMAIL PROTECTED]
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
<[EMAIL PROTECTED]>
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 <[EMAIL PROTECTED]>
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]