Announcement Announcement Module
Collapse
No announcement yet.
Using SpEL and eval to call a controller method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 04:43 AM. Reason: Changed to Solved

  • #2
    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

    Comment


    • #3
      brillant! thank you very much!

      Comment

      Working...
      X