You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jonathan Cowperthwaite <jo...@biomatters.com> on 2006/02/28 00:02:51 UTC
Newbie Question - Best Practice for a Details Page
Hi,
I am using Tapestry 4. What is the best way to create a details page for
an object I will persist via Spring? This question just seems to basic
to ask so my apologies, I have been working through various tutorials
but still fail to grasp what the best practice is.
If you have a bean, how do you create a details page to display and
update its properties
I have the spring service already fetching from the database so I think
I have that correct. My problem is with the details page. On submitting
my form I am getting the following error
/Unable to update OGNL expression '<parsed OGNL expression>' of
$ReportDetails_11@17d56b[ReportDetails] to namebo: target is null
for setProperty(null, "name", namebo)/
I have a basic html form:
<form jwcid="form@Form" listener="listener:onSave">
<table>
<tr>
<td><span jwcid="@FieldLabel"
field="component:name">Name</span></td>
<td colspan="3"><input type="text" jwcid="name@TextField"
value="ognl:report.name" displayName="Name" /></td>
</tr>
<tr>
<td><span jwcid="@FieldLabel"
field="component:description">Description</span></td>
<td colspan="3"><textarea rows="5" cols="50"
jwcid="description@TextArea" value="ognl:report.description"
displayName="Description" /></td>
</tr>
....
With an accompanying class:
public abstract class ReportDetails extends BasePage {
@InjectObject("spring:reportService")
public abstract ReportService getReportService();
@InjectPage("Reports")
public abstract ReportDetails getReportListPage();
public abstract Report getReport();
public abstract void setReport(Report report);
public IPage onSave() {
getReportService().saveReport(getReport());
return getReportListPage();
}
....
}
Is this correct? I can get to the details page from my list page ok, the
list page calls setReport(..) and my details page renders with the
fields populated. When I click submit things fall over, obviously I'm
missing some essential tapestry fundamentals. Am i right to have my
object as a property of the page class and expect it to be populated,
should I be using a bean instead (and what is the difference,
technically or in terms of use, between a property, a bean and an
injected object)?
If there is any patient tapestry guru out there that could point me in
the right direction I would be very grateful.
many thanks
Jonathan
Re: Newbie Question - Best Practice for a Details Page
Posted by Martin Strand <ma...@entcap.se>.
Hello Jonathan.
I'm no guru but maybe I can help anyway.
The problem is when your form is submitted and the form fields are
supposed to be inserted back into in the Report
(getReport().setName(...)). Since this is a new request, your old Report
(the one that was rendered) doesn't exist anymore ("target is null").
If your Report is serializable, you can make Tapestry encode it into the
form and then recreate it again on form submit. Just add this to your
class:
@Persist
public abstract Report getReport();
If the Report can't be serialized or if its a very big object, you can
choose to persist its primary key instead and recreate the object yourself
in pageBeginRender(...) (check the docs).
A property is just a getter/setter pair, you need to populate it yourself
(Tapestry can help you remember it with @Persist).
A bean will be instantiated for you when the getter is first called.
Injected objects are stuff from HiveMind, typically Tapestry
infrastructure stuff such as the HttpServletRequest or whatever.
--Martin
On Tue, 28 Feb 2006 00:02:51 +0100, Jonathan Cowperthwaite
<jo...@biomatters.com> wrote:
> Hi,
>
> I am using Tapestry 4. What is the best way to create a details page for
> an object I will persist via Spring? This question just seems to basic
> to ask so my apologies, I have been working through various tutorials
> but still fail to grasp what the best practice is.
>
> If you have a bean, how do you create a details page to display and
> update its properties
>
>
> I have the spring service already fetching from the database so I think
> I have that correct. My problem is with the details page. On submitting
> my form I am getting the following error
>
> /Unable to update OGNL expression '<parsed OGNL expression>' of
> $ReportDetails_11@17d56b[ReportDetails] to namebo: target is null
> for setProperty(null, "name", namebo)/
>
> I have a basic html form:
>
> <form jwcid="form@Form" listener="listener:onSave">
> <table>
> <tr>
> <td><span jwcid="@FieldLabel"
> field="component:name">Name</span></td>
> <td colspan="3"><input type="text" jwcid="name@TextField"
> value="ognl:report.name" displayName="Name" /></td>
> </tr>
> <tr>
> <td><span jwcid="@FieldLabel"
> field="component:description">Description</span></td>
> <td colspan="3"><textarea rows="5" cols="50"
> jwcid="description@TextArea" value="ognl:report.description"
> displayName="Description" /></td>
> </tr>
> ....
>
> With an accompanying class:
>
> public abstract class ReportDetails extends BasePage {
>
> @InjectObject("spring:reportService")
> public abstract ReportService getReportService();
>
> @InjectPage("Reports")
> public abstract ReportDetails getReportListPage();
>
> public abstract Report getReport();
> public abstract void setReport(Report report);
>
> public IPage onSave() {
> getReportService().saveReport(getReport());
> return getReportListPage();
> }
>
> ....
> }
>
>
> Is this correct? I can get to the details page from my list page ok, the
> list page calls setReport(..) and my details page renders with the
> fields populated. When I click submit things fall over, obviously I'm
> missing some essential tapestry fundamentals. Am i right to have my
> object as a property of the page class and expect it to be populated,
> should I be using a bean instead (and what is the difference,
> technically or in terms of use, between a property, a bean and an
> injected object)?
>
> If there is any patient tapestry guru out there that could point me in
> the right direction I would be very grateful.
>
> many thanks
> Jonathan
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org