Announcement Announcement Module
Collapse
No announcement yet.
Changing Map Value Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Changing Map Value

    Hi guys,

    I was wondering if someone could help me with manipulating values in a Map?

    here's my Person class snippet:

    Code:
        
    public class Person{
    ...
    public Map<String, Object> getProperties() {
            return properties;
        }
    
        protected void setProperties(Map<String, Object> propertyMap) {
            this.properties = new HashMap(propertyMap);
        }
    ...
    The values in this Map get populated by another piece of code, one such key/value pair is:

    key= "riskClass" value= "Standard" (<-- this is the default value)

    I want to be able to update "riskClass"'s value via a jsp using Spring's form tag lib, :
    Code:
    <form:select path="person[0].properties..<MAGIC CODE GOES HERE TO ACCESS 'riskClass' VALUE>" onchange="profileChange('portfolio', false)">
                        <form:option value="Standard"/>
                        <form:option value="Preferred"/>
                    </form:select>
    I've searched these forums and the web back to front to find a good example to no avail .

  • #2
    I am pretty sure you can only bind to index'd objects like List and Set.

    Comment


    • #3
      Please confirm I understand you correctly: you're simply trying to bind the selected value of a drop down to the map "properties" at key "riskClass"?

      Have you tried:
      Code:
      path="person[0].properties['riskClass']"
      Without a complete understanding of what your needs are, I can think of a couple better ways of achieving this.

      Comment


      • #4
        Hi jglynn, thanks for the reply. Yes I've tried that and also:
        Code:
        person[0].properties['riskClass'].value
        but both of them come up with the following exception:

        org.springframework.beans.InvalidPropertyException : Invalid property 'person[0].properties['riskClass']'
        Last edited by jennki; Jan 27th, 2009, 04:29 PM.

        Comment


        • #5
          Btw....
          ...you're simply trying to bind the selected value of a drop down to the map "properties" at key "riskClass"?
          Is correct

          Comment


          • #6
            hmm... if I use EL:
            ${portfolio.person[0].properties['riskClass']}

            I get: 'Standard'

            which is correct.... therefore I can't be mispelling or anything like that :S

            Comment


            • #7
              Can you shed some light on why you're using a map in this fashion to store/capture a Person's properties?

              At first glance, I would suggest creating a class to capture these properties at which point you could simply bind to something like: person[0].properties.riskClass

              Comment


              • #8
                The reason why we've decided to store properties into a hashmap is because we have a rule engine that populates this hashmap with values we need to request depending on what product this person applies for. The rule engine is updated by an administrator via a seperate app. We want to keep the properties dynamic so that the administrator can add in new fields to request along with a particular rule without us having to change the base structure of the Person and Product objects.

                Comment

                Working...
                X