Announcement Announcement Module
Collapse
No announcement yet.
Hashmap in form:form: modify/add/remove entries Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hashmap in form:form: modify/add/remove entries

    Hi everyone
    I have an xml file that contains the configuration data of my application . I also have a form and a controller for the administrators to be able to change the config.

    I have to add a Map<String,String> to this configuration file, this part is not so tricky. Also I use JaxB to map my configuration object with my configuration.xml.

    When an administrator goes to the admin page it first displays the configuration data. then he has to click on one of the "change" buttons to be able to modify a part of the configuration.

    I have read that with spring:bind and c:foreach I could display easily the data from the map. I think with this, that shall also be easy to modify an existing entry. But I m not sure that it will be easy to add, or worse, to remove an entry.

    sth like this
    Code:
    <spring:bind path="hashmap">
    <c:forEach var="parameter" items="${status.value}">
    <c:out value="${parameter.key}"/>
    <c:out value="${parameter.value}"/> <br/>
    </c:forEach>
    </spring:bind>
    Is there a simple way to do this? In a shell: display the hashmap entries, be able to modify entries, be able to add one entry, be able to remove one entry.

    (FYI: the data in the hashmap should not change every day and add or remove an entry shall happen but not so often (so it can be add/remove entry, one by one))
    Last edited by Toinou87; Jul 14th, 2009, 05:05 AM.

  • #2
    Just for your information
    here is how look like a simple part of my configuration (part which only has one string)

    Code:
              <!-- display -->
              <c:if test="${change!='server'}">
                  ${configForm.server } <br />
                  <form:hidden path="server"/>
                  <a href="admin.do?change=server"><spring:message code="admin.change" /></a><br />
              </c:if>
    
              <!-- change -->
              <c:if test="${change=='server'}">
                  <form:input path="server" /> <br />
                  <input type="submit" name="cancel" value="Cancel">
                  <input type="submit" name="submit" value="Submit"><br />
              </c:if>
    and if possible I'd like it to use the less javascript possible (one of my requirements is the application to work as well when javascript is disabled)

    Comment


    • #3
      so,
      I have added this
      Code:
                  <c:forEach var="theEntry" items="${configForm.credentials.credentialMap.entry}" varStatus="loopStatus">
                    <form:input path="credentials.credentialMap.entry[${loopStatus.index }].key" />
                    <form:input path="credentials.credentialMap.entry[${loopStatus.index }].value" />
                    <br />
                  </c:forEach>
      that enables me to display the data (I have put 3 entries in my xml for testing).
      But as soon as I submit the form, I get this error

      Code:
      org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property 'credentials' of bean class [package.models.admin.Configuration]: Value of nested property 'credentials' is null
      I don't understand how it can be null as it displays 3 entries (3 couples of key/value)

      Anyone got a clue? I am stuck with it for hours.

      Comment

      Working...
      X