Tapestry网格展示列表项时遇模板解析弃用元素错误
tapestry:parameter Hey there, let's tackle this Tapestry template error you're facing when trying to display a list in a grid. The error message is pointing to a clear deprecation change in Tapestry 5.3, so let's break down what's going wrong and how to fix it step by step:
1. Understand the Root Cause
Tapestry 5.3 phased out the old unqualified <param> element that was used to pass parameters to components. Instead, it now requires using the fully qualified tapestry:parameter tag with the proper namespace declaration in your template.
2. Update Your Template Code
Let's use a grid component scenario (since you're trying to display a list in a grid) as an example. If your old template had code like this (using the deprecated <param> tag):
<t:grid source="myItemList"> <param name="itemName"> <span class="item-label">${row.name}</span> </param> </t:grid>
You need to replace every instance of <param> with <tapestry:parameter>:
<t:grid source="myItemList"> <tapestry:parameter name="itemName"> <span class="item-label">${row.name}</span> </tapestry:parameter> </t:grid>
3. Ensure the Tapestry Namespace is Declared
Double-check that your template's root <html> tag includes the tapestry namespace declaration. Without this, the template parser won't recognize the tapestry:parameter tag. Here's what it should look like:
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xmlns:tapestry="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
If you're using a newer Tapestry version (like 5.4+), update the XSD version to match (e.g., tapestry_5_4.xsd).
4. Full Working Example for Grid Display
To tie it all together, here's a complete example of displaying a list in a grid with the correct syntax:
Page Class (Java)
package com.mycompany.licenta.pages; import org.apache.tapestry5.annotations.Property; import java.util.List; import com.mycompany.licenta.model.Item; import com.mycompany.licenta.service.ItemService; public class ShowAll { @Property private List<Item> itemList; private final ItemService itemService; // Inject your service via constructor (recommended for Tapestry 5.3+) public ShowAll(ItemService itemService) { this.itemService = itemService; } void setupRender() { // Fetch your list of items from the service itemList = itemService.getAllItems(); } }
Template (ShowAll.tml)
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xmlns:tapestry="http://tapestry.apache.org/schema/tapestry_5_3.xsd"> <head> <title>All Items</title> </head> <body> <h1>Item List</h1> <t:grid source="itemList" rowsPerPage="15" include="name,description,price"> <!-- Customize the price column formatting --> <tapestry:parameter name="price"> <span class="price">$${row.price}</span> </tapestry:parameter> <!-- Add custom action links for each row --> <tapestry:parameter name="actions"> <t:actionlink t:id="edit" context="row.id" class="edit-btn">Edit</t:actionlink> <t:actionlink t:id="delete" context="row.id" class="delete-btn">Delete</t:actionlink> </tapestry:parameter> </t:grid> </body> </html>
This should resolve the template parsing error and get your grid displaying the list correctly.
内容的提问来源于stack exchange,提问作者Alina Ali

