File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes how to access ModelAndView from jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "how to access ModelAndView from jsp" Watch "how to access ModelAndView from jsp" New topic
Author

how to access ModelAndView from jsp

Manu ravi
Greenhorn

Joined: Aug 15, 2012
Posts: 16
I have pasted snippet of the code below:

Code:


now i have a ModelAndView object being returned from the controller which lists the paymentTransIds that i want to display as bold.
Now my problem is how do i iterate through this List being returned by controller and based on that decide to make the column bold or not.

I have a user defined tag lib as


Thanks
I would appreciate any help
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

I dont see any relation between your custom action in jsp and in tld(present).
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Welcome to JavaRanch Manu ravi :)
Manu ravi
Greenhorn

Joined: Aug 15, 2012
Posts: 16
well what present does is that it checks if the bean exists in scope.
for eg:
<c:present name="mybean" property="beanproperty">
if condition is true then do something.
</c:present>

I think my question should have been how do i set a bean to the current _paymentTransId that i have initialized in <tr> so as to access my modelandview object in controller and then iterate through the list returned by the modelandview object
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

ModelAndView is not a JSP class. If it's from a framework, perhaps you should tell us which?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Manu ravi
Greenhorn

Joined: Aug 15, 2012
Posts: 16
I am using spring framework. my flow is: jsp -> bean -> controller -> service method -> DAO
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1649
    
    7

You can access model objects in the JSP as I described in this post:

http://www.coderanch.com/t/587317/Spring/Forms-Spring-MVC#2674378

As for iterating you can do something like I described in this post

http://www.coderanch.com/t/589779/Spring/Edit-object-collection-JSP-view#2686596


[How To Ask Questions][Read before you PM me]
Manu ravi
Greenhorn

Joined: Aug 15, 2012
Posts: 16
I have to pass the modelandview object to a pojo which is then accessed by the jsp as a bean. I am pretty new to this.
I thought my controller returns a modelandview object to jsp. but its apparently not so. the table already uses an iterator. so can I use an iterator within this to validate if the parameter that I have declared in the code above exists in the list returned?


Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1649
    
    7

Post your controller and relevant handler mappings.
Manu ravi
Greenhorn

Joined: Aug 15, 2012
Posts: 16
I am unable to get to the handler mapping for the pojo to controller or jsp to pojo. All I have is a mapping for jsp to controller.

Actually I kind of figured it out. I was trying to get the data in a round about way. I was querying with the wrong parameter. I think its working for now.
Thanks for the help
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1649
    
    7

Ok glad you got it figured out. In one of those links I posted I showed a sample @RequestMapping on a controller. Anything you put on the model should be accessible in the view using the syntax I also demonstrated in the same post.
Manu ravi
Greenhorn

Joined: Aug 15, 2012
Posts: 16
the thing i need to do is that I need to pass _payment that was initialized in tr to a method in controller. Am I correct in assuming _payment in the following code:


can be passed on to the request???
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1649
    
    7

I am sorry but I really don't understand what you are trying to do at all. What taglib is the c prefix bound to? I asked you in my last response to post your Spring Controller code, that would give me a better idea of what Spring is expecting. So far none of what you have posted is Spring related. I don't see any Spring tags in your JSP and I don't see any Controller code. Spring is very flexible and will allow a lot of things but from what I can see you are trying to do things way outside the accepted way.

I don't see any objects being bound to a bean in your jsp I don't see any forms being submitted, I don't see any ajax calls, I don't see you calling the server anywhere. If I did see these things I would not be able to tell you if is correct because you have not shown us your @RequestMapping in your controller. You need to TellTheDetails.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to access ModelAndView from jsp