> Scenario: I am creating Projects and Issues under those projects and have a
> question about passing the projectid around.
>
> Project.tml
> <t:PageLink page="issue/CreateIssue" context="${project.id}">Create
> New Issue</t:PageLink>
>
> CreateIssue.tml
> <t:BeanEditForm t:id="issue" object="newIssue"
> submitLabel="message:submitCreateIssueText" exclude="id" add="project">
> <t:Parameter name="project">
> <input name="projectId" value="${project.id}"/>
> </t:Parameter>
> </t:BeanEditForm>
>
> Q1: notice, I have to add the projectId parameter. Also, 'newIssue' does NOT
> have a projectId field. Submitting this form takes me to onSuccess where I'd
> like to to retrieve the Project, create the Issue, call
> issue.setProject(project) and then save the issue. But how do I retrieve the
> projectId field since it is not part of my Issue entity?
>
> Q2: after saving the new Issue, I'd like to return to the project screen. To
> do that, I'd like to forward to a page/handler by passing the 'projectId'
> again. How do I do that from onSuccess? I return a class - but how do I
> include a parameter?
>
> I think I am missing something. onActivate works when I am rendering a page
> - but I'm not sure what similar method gets called while Posting ... and
> before onSuccess where I can pull off the projectId.
>
Sure, onActivate is also called while posting, and pair of
onActivate/onPassivate helps much here and you additional parameter can be
removed from the beaneditform.
Code in CreateIssue.java:
private int projectId;
void onActivate(int projectId) {
this.projectId = projectId;
}
int onPassivate() {
return this.projectId;
}
Then this projectId will be rendered as a hidden value in the form like
"input.type='hidden' name='t:ac' value='your project id'". So you can directly
use this.projectId inside onSuccess.
@InjectPage
private Project projectPage;
Project onSuccess() {
// other logic
projectPage.onActivate(projectId); // other set style methods are ok too.
return projectPage;
}
In Project.java, apply the same code:
private int projectId;
void onActivate(int projectId) {
this.projectId = projectId;
}
int onPassivate() {
return this.projectId;
}
> Furthermore, is there a lifecycle method I can implement that would attach
> projectId to the request so that the following page can get it? Maybe during
> onPassivate? Just not sure how to pass it.
Refer to Geoff's jumpstart
http://jumpstart.doublenegative.com.au:8080/jumpstart/, there are some examples
on how to pass value between pages.
Forget the request and always use onActivate/onPassivate/InjectPage and other
javabean style to set values between pages as above.
>
> Thanks for any suggestions,
>
> -Luther
>