Announcement Announcement Module
Collapse
No announcement yet.
Binding form:select items at runtime Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding form:select items at runtime

    Guys...

    After a few fruitless hours of searching, I've yet to find an answer. So i throw this out in the hope that someone smarter than I can show me where I'm going wrong..

    Is there a way to bind the "items" tag to a value in the referenceData at runtime? That is... in my form, i have a series of attributes being rendered and if they are of type "drop-down", I'm rendering a <form:select/> element with hopefully a reference to a String array in the reference data.

    My current referenceData method in form controller has:

    Code:
    protected Map referenceData(HttpServletRequest request, Object command,
    			Errors errors) throws Exception {
    ...
    //obtain reference to my command object.
    Search search = (Search) command;
        //create a map to contain my "value-assistance"
        Map va = new LinkedHashMap();
        //iterate through the attributes on my search
        for (int i = 0, ii = search.getAttributes().length; i < ii; i++) {
           Attribute a = search.getAttributes()[i];
            // if we have a control of type COMBO; retrieve the list reference
           // data from the listManager. The listManager (singleton bean) returns a String[] array of value-assistance values.
          if (Attribute.CONTROLTYPE_COMBO.equalsIgnoreCase(a.getControltype())) {
    	va.put(a.getName(), listManager.getMultiList(a.getName(),null));
          }
        }
        map.addObject("va", va);


    This means, I'll have say.. a Map in referenceData containing:

    list1 = {"A","B","C"}
    list2 = {"D", "E", "F"}
    etc.


    When i render the jsp, if i have a controltype = combo; then i'm rendering the following:

    Code:
    <form:select id="${a.name}" path="attributes[${attrid.index}].value" items="????/>
    its the "items" that I can't quite figure out...

    ie.
    Code:
    items="${va.list1}"
    will work, it can retrieve the value from the map based on the referenceData available in the map. The list will contain A,B,C etc.

    what i'd REALLY like to be able to do though is retrieve this at run-time... something like.. (doesn't work)
    Code:
    items="${va.${a.name}}"
    where. ${a.name} is the name of the list i'm trying to retrieve.


    Binding the items array at runtime rather than having to hard-code it - or make it a property of my Attribute class (since i'd like to retrieve these from the listManager singleton bean).

    Will attach beer and peanuts for anyone that can assist!

    Hope you can help.

    A.

  • #2
    I am not sure what exactly you are asking. Are you saying that in some cases you want to use list1 and other cases list2? You could have both lists in the jsp and hide decide which to show based on some criteria...not sure what your trying to do though.

    Comment


    • #3
      Don't think you can do it...

      I could be wrong, but if I understand correctly, you essentially need to have your page 'rendered' twice. The first time, the page would get parsed and the

      ${a.name}

      part of

      ${va.${a.name}}

      would get evaluated. lets say that that returns "foo". You then are hoping that the page would get evaluated again, this time, you would be evaluating:

      ${va.foo}

      If I understand you correctly, I don't think that will work. But, I would love to hear someone prove me wrong, because it would be pretty slick.

      Chris

      Comment

      Working...
      X