Results 1 to 3 of 3

Thread: Using SpEL and eval to call a controller method

  1. #1
    Join Date
    Mar 2011
    Location
    Strasbourg,France
    Posts
    24

    Default [Solved]Using SpEL and eval to call a controller method

    Hi,
    I was wondering if it was possible to call a controller method using the <s:eval> tag from a JSP page, a bit like the way it's done in JSF.



    Code:
    @Controller(value="planesController")
    @RequestMapping({"/planes"})
    public class PlanesController {
    
    	@Autowired
    	private PlanesDAO planesDAO;
    	
    	
    
    	public List<Plane> allPlanes(){
    		
    		return planesDAO.getAll();
    	}

    Code:
    <sf:form>
    <s:eval expression="planesController.allPlanes()" var="planes" />
    
    <sf:checkboxes items="${planes}" path="planes"  id="avions"/>
    	     
    </sf:form>

    I keep getting the exception :

    Code:
    org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'planesController' cannot be found on null
    I know I can use model.addAttribute but I call this method from several JSP pages and I thought one of the of the <s:eval> tag was to allow access to beans from views.

    I'm using Spring 3.0.5


    Thanks in Advance
    Last edited by ufasoli; May 2nd, 2011 at 03:43 AM. Reason: Changed to Solved

  2. #2
    Join Date
    Aug 2004
    Posts
    18

    Default

    You have to prefix the bean name with the character @

    This
    <s:eval expression="@planesController.allPlanes()" var="planes" />
    should do the job.

    You can add parameters too. Something like this should work
    <s:eval expression='@planesController.allPlanes(true, "aParameter", 10)' var="planes" />

    You find more information in the documentation: http://static.springsource.org/sprin....html#d0e12033

  3. #3
    Join Date
    Mar 2011
    Location
    Strasbourg,France
    Posts
    24

    Talking

    brillant! thank you very much!

Tags for this Thread

Posting Permissions

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