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");
        }

        public DepartmentSelectionModel(List depts) {

                this();

                if (depts == null)
                        return;

                departmentList = depts;
        }

        public int getOptionCount() {
                return departmentList.size();
        }

        public Object getOption(int index) {
                return departmentList.get(index);
        }

        public String getLabel(int index) {
return ((UserDepartment) departmentList.get (index)).getDepartmentName();
        }

        public String getValue(int index) {
return ((UserDepartment) departmentList.get(index)).getDepartmentId ().toString();
        }

        public Object translateValue(String index) {
                return dao.findByDepartmentId(Integer.parseInt(index));
        }

        public List getDepartmentList() {
                return departmentList;
        }

}
/* models' class */



On 8/15/06, Nick Westgate wrote:
> Hi Waimin.
>
>  > The BikeMaker example above uses StringPropertySelectionModel and
> > String[] objects for the drop-down selection lists. However, I modified > > my program to use custom PropertySelectionModel(s) and custom objects
>  > as value objects in the models.
>
> There are two versions of the demo and one of them uses custom models,
> *not* StringPropertySelectionModel:
>
> http://lombok.demon.co.uk/tapestryDemo/welcome?service=page/ TestDSLComponent2 > http://lombok.demon.co.uk/tapestryDemo/welcome?service=page/ TestDSLComponent2Source
>
> You should look carefully at that example.
>
> If you still can't find the problem please post your .page file and
> perhaps the child model code.
>
> Cheers,
> Nick.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to