Announcement Announcement Module
Collapse
No announcement yet.
Accessing referenceData from custom JSTL Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing referenceData from custom JSTL

    Is there any way to access a form's model (set by referenceData()) from within a JSTL class?

    I would like to be able to reference an entry in the model by the Spring convention within a JSP
    Code:
    <myTagLib&#58;myTag 
      ...
      tagAttribute="$&#123;model.myCollection&#125;"
      ...
    />
    I seem to be able to resolve the "${status.*}" properties OK, but I cannot find a way to retrieve the model entries.

    Any ideas?

    Philip

  • #2
    Since you are using that within your own tag, you will have to program it.. E.g.:
    Code:
    	/**
    	 * This method will try to replace the expressions that are set between $&#123; and &#125; with the bean values that it
    	 * corresponds to. Since the parameter can contain more then just the expression, this must be done in a loop and 
    	 * the parameter string must be parsed for each $&#123;&#125; combo &#40;e.g. 
    	 * onClick="return confirm&#40;'Replace $&#123;bean.name&#125; with $&#123;bean.description&#125;?'&#41;;"
    	 * @param parameter
    	 * @return
    	 */
    	private String convertExpression&#40;String parameter&#41; &#123;
    		while&#40; ExpressionEvaluationUtils.isExpressionLanguage&#40;parameter&#41; &#41; &#123;
    			String tobeReplaced = StringUtils.findBetween&#40;parameter, "$&#123;", "&#125;"&#41;;
                StringBuffer sb = new StringBuffer&#40;&#41;;
    			sb.append&#40;"$&#123;"&#41;.append&#40;tobeReplaced&#41;.append&#40;"&#125;"&#41;;
    
    			String value = null;
    			try &#123;
    				value = &#40;String&#41; ExpressionEvaluationUtils.evaluateString&#40;"", sb.toString&#40;&#41;, pageContext&#41;;
    			&#125; catch &#40;JspException e&#41; &#123;
    				value = "";
    			&#125;
    			parameter = StringUtils.replace&#40;parameter, sb.toString&#40;&#41;, value&#41;;
    		&#125;
    		return parameter;
    	&#125;
    Gr
    Ronald

    Comment


    • #3
      Hi Ronald

      Thanks for the response, but I'm not sure it answers my question - It seems that ExpressionEvaluationUtils only has access to the String (or boolean/Integer) representation of properties on the command object - I'm hoping to grab any class of object from the referenceData (in this particular instance, a Collection).

      i.e. Once I have the name (key) of the model entry, how do I actually retrieve it? I thought the model was somehow attached to the errors object, but I can't find where I saw that documented or any way of accessing it.

      Philip

      Comment


      • #4
        Aha! The solution...

        This post http://forum.springframework.org/showthread.php?t=12480 gave me a clue:

        Code:
        HttpServletRequest request = (HttpServletRequest)pageContext.getAttribute(PageContext.REQUEST);
                Object modelEntry = request.getAttribute("myCollection");
        Philip
        Last edited by robyn; May 19th, 2006, 06:38 AM.

        Comment

        Working...
        X