Announcement Announcement Module
Collapse
No announcement yet.
Failed to show data on refresh page. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Failed to show data on refresh page.

    Hi

    With spring mvc 3.1, I used javascript to refresh a parent page from its child page, but the data on the parent page is lost.

    Here is the controller:

    Code:
    @RequestMapping(value = "/categories_image/categories_image_update", method = RequestMethod.GET)
        public String update(CategoryPageBean categoryPageBean, 
                        @RequestParam("categoryId") String categoryId,
                        @RequestParam("categoryRelation") String categoryRelation, 
                        @RequestParam("categoryName") String categoryName, 
                        HttpSession session, Model model) {
    
    
                      if (StringUtils.isEmpty(categoryId)) {
                            throw new RuntimeException("==categoryId is NULL==");
                        }
                      
                      Collection<CategoryImages> categoryImageCollection =
                             categoryImageService.findImagesByCategoryId(Integer.parseInt(categoryId), 0, categoryImageService.count());
                      List<CategoryImages> categoryImageList = new ArrayList<CategoryImages>();
                      categoryImageList.addAll(categoryImageCollection);
                      
                      CategorySubcategories c = categoryService.findByCategoryId(Integer.parseInt(categoryId));
                      sessionCategoryPageBean.setCategoryDesc(c.getCategoryDesc());
                      sessionCategoryPageBean.setCategoryName(c.getCategoryName());
                      sessionCategoryPageBean.setId(c.getCategoryId().toString());
                      
                      model.addAttribute("categoryPageBean", sessionCategoryPageBean)
                              .addAttribute("categoryImageList", categoryImageList)
                              .addAttribute("parentPath", "../categories/categoryPage")
                              .addAttribute("parentPathName", "Manage Category")
                              .addAttribute("currentPageName", currentPageName)
                              .addAttribute("categoryId", categoryId);
                      
    	return "categories_image/categories_image_update";
        }
    session bean:
    Code:
    @Component
    @Scope("session")
    public class CategoryPageBean{
    
        private static final Logger logger = Logger.getLogger(CategoryPageBean.class);
    
        private byte[] imageTmp = null;
    
        private String parentCategory = "";
        private String siblingCategory = "";
        private String childCategory = "";
        
        private boolean parent=false, sibling=false, child=false;
    
        private String user = "";
    
        @NotEmpty (message = "categoryname.empty.field")
        private String categoryName = "";
        @NotEmpty (message = "categorydesc.empty.field")
        private String categoryDesc = "";
        
        private String filename = "";
        private CommonsMultipartFile fileData;
        private String Id = "";
    
        public CategoryPageBean() {
        }
        
    
        public byte[] getImageTmp() {
            return imageTmp;
        }
    
        public void setImageTmp(byte[] imageTmp) {
            this.imageTmp = imageTmp.clone();
        }
        
         public boolean isChild() {
            return child = StringUtils.isEmpty(this.parentCategory) && StringUtils.isEmpty(this.siblingCategory) && StringUtils.isNotEmpty(this.childCategory);
        }
    
        public void setChild(boolean child) {
            this.child = child;
        }
    
        public boolean isParent() {
            return parent = StringUtils.isEmpty(this.siblingCategory) && StringUtils.isEmpty(childCategory) && StringUtils.isNotEmpty(this.parentCategory);
        }
    
        public void setParent(boolean parent) {
            this.parent = parent;
        }
    
        public boolean isSibling() {
            return sibling = StringUtils.isEmpty(parentCategory) && StringUtils.isEmpty(childCategory) && StringUtils.isNotEmpty(this.siblingCategory);
        }
    
        public void setSibling(boolean sibling) {
            this.sibling = sibling;
        }
        
        public String getChildCategory() {
            return childCategory;
        }
    
        public void setChildCategory(String childCategory) {
            this.childCategory = childCategory;
        }
    
        public String getSiblingCategory() {
            return siblingCategory;
        }
    
        public void setSiblingCategory(String siblingCategory) {
            this.siblingCategory = siblingCategory;
        }
        
        public String getCategoryDesc() {
            return categoryDesc;
        }
    
        public void setCategoryDesc(String categoryDesc) {
            this.categoryDesc = categoryDesc;
        }
    
        public String getCategoryName() {
            return categoryName;
        }
    
        public void setCategoryName(String categoryName) {
            this.categoryName = categoryName;
        }
        
                    
       public String getParentCategory() {
            return parentCategory;
        }
    
        public void setParentCategory(String parentCategory) {
            this.parentCategory = parentCategory;
        }
    
        public String getUser() {
            return user;
        }
    
        public void setUser(String user) {
            this.user = user;
        }
       
        //*************************************************
        public String getId() {
                return Id;
        }
    
        public void setId(String Id) {
            this.Id = Id;
        }
    
        public String getFilename() {
                return filename;
        }
    
        public void setFilename(String filename) {
                this.filename = filename;
        }
    
        public CommonsMultipartFile getFileData() {
                return fileData;
        }
    
        public void setFileData(CommonsMultipartFile fileData) {
                this.fileData = fileData;
        }
        //*************************************************
    
        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final CategoryPageBean other = (CategoryPageBean) obj;
            if ((this.parentCategory == null) ? (other.parentCategory != null) : !this.parentCategory.equals(other.parentCategory)) {
                return false;
            }
            if ((this.user == null) ? (other.user != null) : !this.user.equals(other.user)) {
                return false;
            }
            if ((this.categoryName == null) ? (other.categoryName != null) : !this.categoryName.equals(other.categoryName)) {
                return false;
            }
            if ((this.categoryDesc == null) ? (other.categoryDesc != null) : !this.categoryDesc.equals(other.categoryDesc)) {
                return false;
            }
            return true;
        }
    
        @Override
        public int hashCode() {
            int hash = 7;
            hash = 41 * hash + (this.parentCategory != null ? this.parentCategory.hashCode() : 0);
            hash = 41 * hash + (this.user != null ? this.user.hashCode() : 0);
            hash = 41 * hash + (this.categoryName != null ? this.categoryName.hashCode() : 0);
            hash = 41 * hash + (this.categoryDesc != null ? this.categoryDesc.hashCode() : 0);
            return hash;
        }
    parent page:

    Code:
    <c:url var="updateUrl" value="/categories_image/categories_image_update" />
                <form:form id="form" name="categories_image_update_form" modelAttribute="categoryPageBean" method="POST" action="${updateUrl}">
                  <div class="success">Category Edit form submitted!<br>
                  <strong>Haliluya.</strong> </div>
                  <fieldset>
                      <span class="label">Category Name:</span>
                      <label class="name">
                      <form:input type="text" path="categoryName" class="fleft"/>
                            <span class="error">*Description is too short.</span> <span class="empty">*This field is required.</span> </label>
                      <div class="clear"></div>
                    <span class="label">Category Description:</span>
                    <label class="message">
                      <form:textarea path="id" />
                      <span class="error">*Description is too short.</span> <span class="empty">*This field is required.</span> </label>
                      <div class="clear"></div>
    value in the textarea (categoryDesc) is not shown. Further checking its session bean, the printed value of categoryPageBean shown that categoryDesc is empty. Only couples of fields eg. categoryName, imageTmp has value.

    In controller, I tried to manually assign value to Id, and replace categoryDesc by id in the textarea, but id also becomes empty.

    What have I done wrong in my model and how to change it? it seems very buggy.
    Any suggestion is very appreciated.
    Sam
Working...
X