Announcement Announcement Module
Collapse
No announcement yet.
Updating data to a HashMap Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Updating data to a HashMap

    Hi,

    I have a commandClass(propery in servlet.xml) which has a HashMap as private variable.
    I want to store the data into the Hashmap dynamically i.e, key and value should be from the jsp form.

    I am attaching a snippet of the jsp:
    Code:
    <form:form commandName="hashMapCommand" method="POST" action="LoginPage.htm">
                 
                  <spring:bind path="hashMapCommand.hashMapData['$UserName']">
                   echo $UserName
                    <input type="text" name="${status.expression}" id="${status.expression}" value="${status.value}"/>
                  </spring:bind>
    
                 
                 <spring:bind path="hashMapCommand.hashMapData['$Password']">
                    <input type="password" name="${status.expression}" id="${status.expression}" value="${status.value}"/>
                  </spring:bind>
                    <input type="submit" class="button" name="save" value="Login" />  
               </form:form>
    This gives me the following error on click of the save button

    org.springframework.beans.NotReadablePropertyExcep tion: Invalid property 'UserName' of bean class [au.com.alcatel.inm.xdm.web.mvc.controller.HashMapC ommand]: Bean property 'UserName' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    at org.springframework.beans.BeanWrapperImpl.getPrope rtyValue(BeanWrapperImpl.java:540)
    at org.springframework.beans.BeanWrapperImpl.getPrope rtyValue(BeanWrapperImpl.java:532)
    at org.springframework.validation.AbstractPropertyBin dingResult.getActualFieldValue(AbstractPropertyBin dingResult.java:79)

    Any Help is appreciated,

    Thanks and Regards,
    Maya

  • #2
    It seems that you did not qualify your HashItems setter/getter properly so Spring is not able to retrieve the values.

    As you need some login mechanism why not use spring security(acegi) easy to configure and usually it fits your demands...?

    Comment


    • #3
      To expand on what he said, you need something like the following in your method that handles the GET request:
      Code:
      Map hash = setUpMyHashMap();
      
      ModelAndView mav = new ModelAndView("myViewName");
      mav.addObject("hashMapCommand", hash);
      You need to add the hash to the Model or ModelAndView.

      Alternatively, you could add the user name and password directly to the Model or ModelAndView since they are Maps under the covers. But as nOiDStaRr alludes to, that's probably not a "best practice."

      Comment


      • #4
        Hi,

        I take your comments about the security framework. But i am not doing it with Security. (Just trying this example thats all) .
        The intention of doing this is to avoid creating different entity object.
        I will try what you mentioned, and update.

        Thanks and Regards,
        Maya

        Comment

        Working...
        X