UsersByDepartmentSelectionModel.java (and
DepartmentSelectionModel.jav)
looks suspcious.
The UsersByDepartmentSelectionModel.getOption method
returns a value
from userLists, but
UsersByDepartmentSelectionModel.translateValue returns
a value using a dao.
You might like to test
UsersByDepartmentSelectionModel in a standalone
PropertySelection
component : select an entry from the drop list. Print
the selected value in a form
listener method.
Shing
--- Waimun Yeow <[EMAIL PROTECTED]> wrote:
> The second version of the demo helped me to correct
> the way custom
> objects are passed in the selection property model
> classes. I have
> made the changes in my selection model classes and
> also the
> pageBeginningRender() method. However, I am still
> having the same
> problem. I have posted the .page and codes below.
>
> -waimun
>
> <!-- .page -->
> <property-specification name="toDepartment"
> type="project6.model.UserDepartment"
> persistent="no" />
>
> <property-specification name="user"
> type="project6.model.UserAccount"
> persistent="no" />
>
> <property-specification
> name="departmentSelectionModel"
>
>
type="org.apache.tapestry.form.IPropertySelectionModel"
>
> persistent="no" />
>
> <property-specification
> name="usersByDepartmentList"
> type="java.util.List" initial-value="new
> java.util.ArrayList()"
> persistent="no" />
>
>
>
> <property-specification name="userDepartmentDao"
> type="project6.dao.UserDepartmentDao">
>
>
global.getApplicationContext().getBean("userDepartmentDao")
> </property-specification>
>
> <property-specification name="userAccountDao"
> type="project6.dao.UserAccountDao">
>
>
global.getApplicationContext().getBean("userAccountDao")
> </property-specification>
> <component id="referralForm" type="Form">
> <binding name="listener"
> expression="listeners.formSubmit"/>
> </component>
> <component id="deptSelection"
> type="PropertySelection">
> <binding name="value" expression="toDepartment" />
> <binding name="model"
> expression="departmentSelectionModel" />
> <binding name="disabled" expression="false" />
> <static-binding name="submitOnChange"
> value="false" />
> </component>
>
> <component id="userSelection"
> type="man:DynamicSelectionList">
> <binding name="parent"
> expression="components.deptSelection" />
> <binding name="value" expression="user" />
> <binding name="childList"
> expression="usersByDepartmentList" />
> </component>
>
> <!-- .page -->
>
> /* method's code for page */
>
> public void pageBeginRender(PageEvent event) {
>
> List allDepartments =
> getUserDepartmentDao().findAll();
>
> if (getDepartmentSelectionModel() == null) {
> setDepartmentSelectionModel(new
> DepartmentSelectionModel(
> allDepartments));
> }
>
> if (getUsersByDepartmentList().size() == 0) {
>
> DepartmentSelectionModel deptModel =
> (DepartmentSelectionModel)
> getDepartmentSelectionModel();
>
>
> for (Iterator it =
> deptModel.getDepartmentList().iterator(); it
> .hasNext();) {
>
>
> UserDepartment d = (UserDepartment) it.next();
>
> List usersByDepartment =
> getUserAccountDao().findByDepartment(d);
>
> if (usersByDepartment.size() == 0) {
> List a = new ArrayList();
> a.add(getUserAccountDao().findByUsername("Waimun
> Yeow"));
> usersByDepartment = a;
> }
>
> getUsersByDepartmentList().add(
> new
> UsersByDepartmentSelectionModel(usersByDepartment));
>
> }
>
> }
>
>
> if (getToDepartment() == null) {
> setToDepartment((UserDepartment)
> getDepartmentSelectionModel
> ().getOption(4));
> }
>
> }
> /* method's code for page */
>
> /* models' class */
> public class UsersByDepartmentSelectionModel
> implements
> IPropertySelectionModel, Serializable {
>
> private List usersList = new ArrayList();
>
> private static UserAccountDao dao;
>
> public UsersByDepartmentSelectionModel() {
>
> XmlBeanFactory factory = new XmlBeanFactory(new
> ClassPathResource(
> "DaoContext.xml"));
>
> dao = (UserAccountDao)
> factory.getBean("userAccountDao");
> }
>
> public UsersByDepartmentSelectionModel(List users)
> {
>
> this();
>
> if (users == null)
> return;
>
> usersList = users;
> }
>
> public int getOptionCount() {
> return usersList.size();
> }
>
> public Object getOption(int index) {
> return usersList.get(index);
> }
>
> public String getLabel(int index) {
> return ((UserAccount)
> usersList.get(index)).getUserName();
> }
>
> public String getValue(int index) {
> return ((UserAccount)
> usersList.get(index)).getUserId().toString();
> }
>
> public Object translateValue(String index) {
> return dao.findByUserId(Integer.parseInt(index));
> }
>
> public List getUsersList() {
> return usersList;
> }
>
> }
>
> public class DepartmentSelectionModel implements
> IPropertySelectionModel, Serializable {
>
> private List departmentList = new ArrayList();
>
> private static UserDepartmentDao dao;
>
> public DepartmentSelectionModel() {
>
> XmlBeanFactory factory = new XmlBeanFactory(new
> ClassPathResource(
> "DaoContext.xml"));
>
> dao = (UserDepartmentDao)
> factory.getBean("userDepartmentDao");
> }
>
=== message truncated ===
Home page :
http://uk.geocities.com/matmsh/index.html
___________________________________________________________
Inbox full of spam? Get leading spam protection and 1GB storage with All New
Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]