As you already know, the component used to do this kind of job in Tapestry is PropertySelection. Let's configure it in the CelebritiesList page. Here is the addition to the template: <form action="" jwcid="@Form"> <select jwcid="selectCelebrity"> <option value="1">Angelina Jolie</option> <option value="2">Bill Gates</option> </select> <input type="submit" value="Save"/> </form> Let's add a property to store the selected celebrity in the page class. We want some other page to be able to display the selected celebrity afterward, so it will be an ASO: @InjectState("celebrityOfTheWeek") public abstract Celebrity getCelebrityOfTheWeek(); You already know how to configure an ASO in hivemodule.xml, but here is the addition, just to help you: <contribution configuration-id="tapestry.state.ApplicationObjects"> <state-object name="celebrityOfTheWeek" scope="session"> <create-instance class="com.devshed.tapestry.celebrities.Celebrity"/> </state-object> </contribution> Finally, we need to configure the component in the page specification: <component id="selectCelebrity" type="PropertySelection"> <binding name="model" value="celebrityModel"/> <binding name="value" value="celebrityOfTheWeek"/> </component> The last piece of configuration is to provide a model, which should be an implementation of the IPropertySelectionModel interface. We don't have a proper model yet, so let's just return a null: public IPropertySelectionModel getCelebrityModel() { return null; } This will not work however as we need to return a real model. To summarize what we have already done, you can see that the PropertySelection component per se is quite simple, it doesn't take much effort to configure. It is the model that requires the most thought this collaboration, and we do need to write some code to implement it.
blog comments powered by Disqus |
|
|
|
|
|
|
|