Yes you are right. It almost seems that Tree component has Session-State
associated with individual Page. To solve this I can only have One Page Tied
to Tree component and that Page should inject required component based on
condition satisfied. Although, that is not very flexible solution and not
good for overall health of project as I will have so many pages over time
and they will require Common-Tree component. I am not sure how to solve
this. I have tried every possible solution I can think of. I have tried this
too... But it didn't work... I guess it's time somebody from Tapestry team
who worked on Tree component, chime in!

public class SerializableTreeModel<T> extends DefaultTreeModel<T> implements
Serializable {

        private static final long serialVersionUID = 9121281508748183989L;

        public SerializableTreeModel(ValueEncoder<T> encoder, 
TreeModelAdapter<T>
adapter, List<T> roots) {
                super(encoder, adapter, roots);
        }

        public SerializableTreeModel(ValueEncoder<T> encoder, 
TreeModelAdapter<T>
adapter, T root) {
                super(encoder, adapter, root);
        }

}



public class PortalAccessTree extends UserSessionManagement {
        
        @InjectComponent
        private Tree tree;  
        
        /**
         * Always initialize component using @SetupRender annotation. 
         * @throws VCloudException 
         */
        @SetupRender
    void initializeValue() throws VCloudException
    {   
                        
        }

        /**
         * Clear Action link on PortalAccessTree.tml invokes this method. 
         */
        void onActionFromClear() {
                tree.clearExpansions();
        }

}



public class Index extends ILandBasePage implements IntermediatePage
{

void onValidateFromLogin() {
                
                if(form.getHasErrors()) {
                        return;
                }
                
                try {
                        
                        WebUser userSessionObject = new WebUser(username, 
password);
                        LoginUtil.doLogin(userSessionObject);           
                        this.setUser(userSessionObject);        
                        
                        
TreePreprationHelperUtil.prepareAccessTree(this.getUser().getRootNode(),
getUser().getPrimaryUser().getCloudDirectorUsers());            
                        
                        this.setValueWrapperModel(getValueWrapperModel());
                        
                } catch (LoginException le) {
                        log.error("Login Exception occured : "+le);
                        form.recordError(usernameField, le.getMessage());
                }catch (Exception e) {          
                        log.error("Login Exception occured : "+e);
                        form.recordError(usernameField, "Login failed because 
of some unknown
exception was thrown by system. "+
                                                                                
        "Please try again later.");                     
                }       
                
        }
        
        public TreeModel<ValueWrapper> getValueWrapperModel() {
                ValueEncoder<ValueWrapper> encoder = new 
ValueEncoder<ValueWrapper>() {
                                                                                
                public String toClient(ValueWrapper value) {
                                                                                
                        return value.getUuid();
                                                                                
                }
                                                                        
                                                                                
                public ValueWrapper toValue(String clientValue) {
                                                                                
                        return getUser().getRootNode().seek(clientValue);
                                                                                
                }
                                                                                
        };

                return new SerializableTreeModel<ValueWrapper>(encoder, new
ValueWrapperTreeModelAdapter(), getUser().getRootNode().getChildren());
        }
        
}


public abstract class UserSessionManagement {
        
        @SessionState
        private User user;      
        private boolean userExists;     
        
        public User getUser() {
                return user;
        }
        protected void setUser(User user) {
                this.user = user;
        }       
        public boolean isUserExists() {
                return userExists;
        }       
        
        public boolean isLoggedIn() {
                return getPrimaryUser() != null && 
getPrimaryUser().isLoggedIn();
        }
                
        public PrimaryUser getPrimaryUser() {
                return userExists ? user.getPrimaryUser() : null;
        }
        
        
        @SessionState   
        private ValueWrapper valueWrapper;
        private boolean valueWrapperExists;
        public ValueWrapper getValueWrapper() {
                return valueWrapper;
        }
        public void setValueWrapper(ValueWrapper valueWrapper) {
                this.valueWrapper = valueWrapper;
        }
        public boolean isValueWrapperExists() {
                return valueWrapperExists;
        }
        
        
        
        @SessionState 
        private TreeModel<ValueWrapper> valueWrapperModel;
        public TreeModel<ValueWrapper> getValueWrapperModel() {
                return valueWrapperModel;
        }
        public void setValueWrapperModel(TreeModel<ValueWrapper> 
valueWrapperModel)
{
                this.valueWrapperModel = valueWrapperModel;
        }

}



public interface User extends Serializable {
        
        PrimaryUser getPrimaryUser();   
        void setPrimaryUser(PrimaryUser primaryUser);
        
        List<String> getWarningMessages();      
        boolean isLoggedIn();
        
        ValueWrapper getRootNode();
        void setRootNode(ValueWrapper rootNode);
        
}



public abstract class UserImpl implements User {

        private static final long serialVersionUID = 682425753665404689L;

        private PrimaryUser primaryUser;
        
        private List<String> warningMessages;
        
        private ValueWrapper rootNode;
        
        public List<String> getWarningMessages() {
                if(warningMessages == null) {
                        warningMessages = new ArrayList<String>();
                }
                return warningMessages;
        }
                
        public PrimaryUser getPrimaryUser() {
                if(primaryUser == null) {
                        return new PrimaryUser();
                }
                return primaryUser;
        }
        public void setPrimaryUser(PrimaryUser primaryUser) {
                this.primaryUser = primaryUser;
        }
        
        public boolean isLoggedIn() {
                return primaryUser != null && primaryUser.isLoggedIn();
        }
        
        public String toString() {
                return "["+
                   "primaryUser="+primaryUser+","+
                                "isLoggedIn()="+isLoggedIn() +
                                "]";
        }
        
        public ValueWrapper getRootNode() {             
                if(this.rootNode == null) {
                        this.rootNode = new ValueWrapper("Root", null, null);
                }
                return this.rootNode;
        }

        public void setRootNode(ValueWrapper rootNode) {
                this.rootNode = rootNode;               
        }
        
}



public class WebUser extends UserImpl {

        private static final long serialVersionUID = -8520309814358124946L;

        public WebUser (String portalUsername, String portalPassword) {         
                PrimaryUser primaryUser = new PrimaryUser();    
                primaryUser.setPortalLoginRequired(true);
                primaryUser.setPortalUsername(portalUsername);
                primaryUser.setPortalPassword(portalPassword);
                this.setPrimaryUser(primaryUser);
        }       

}



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tree-Session-Management-Issue-tp5715132p5715205.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to