Results 1 to 4 of 4

Thread: Accessing referenceData from custom JSTL

  1. #1
    Join Date
    Aug 2004
    Posts
    9

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    29

    Default

    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

  3. #3
    Join Date
    Aug 2004
    Posts
    9

    Default

    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

  4. #4
    Join Date
    Aug 2004
    Posts
    9

    Default

    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 at 05:38 AM.

Similar Threads

  1. Replies: 2
    Last Post: Sep 1st, 2009, 09:24 AM
  2. Replies: 2
    Last Post: Aug 2nd, 2006, 10:18 PM
  3. Replies: 3
    Last Post: Nov 15th, 2005, 03:24 PM
  4. Replies: 3
    Last Post: Aug 16th, 2005, 11:53 AM
  5. Replies: 0
    Last Post: Oct 26th, 2004, 09:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •