aspose file tools*
The moose likes Servlets and the fly likes Populating values for form input elements using servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Populating values for form input elements using servlet" Watch "Populating values for form input elements using servlet" New topic
Author

Populating values for form input elements using servlet

Dilip Ganesh
Greenhorn

Joined: Sep 30, 2011
Posts: 24
Hi all,

I needs to populate values for listboxes , textboxes .. almost all the form input elements from my servlet . Because sending the object to the JSP page and populating the values for the input elements there (using any tag libraries JSTL) i found it difficult.

Is there anyway for setting all the Input Element values from the servlet itself? For example if i needs to set the value for textfield , then in my servlet



In my jsp page

or using any tag library also fine.

How can we achieve this type of functionality or any framework is available? Please help me.

Thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Dilip Ganesh wrote: Because sending the object to the JSP page and populating the values for the input elements there (using any tag libraries JSTL) i found it difficult.

It should not be difficult. So instead of trying to find some other weird way of doing it -- which is most likely to be even more difficult because it's not natural -- makes no sense at all.

The best approach would be to try to find out what you are doing wrong that makes it difficult.

So what difficulties did you run into?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dilip Ganesh
Greenhorn

Joined: Sep 30, 2011
Posts: 24
Bear Bibeault wrote:
Dilip Ganesh wrote: Because sending the object to the JSP page and populating the values for the input elements there (using any tag libraries JSTL) i found it difficult.

It should not be difficult. So instead of trying to find some other weird way of doing it -- which is most likely to be even more difficult because it's not natural -- makes no sense at all.

The best approach would be to try to find out what you are doing wrong that makes it difficult.

So what difficulties did you run into?


Thank you so much for your quick reply. In my servlet i am calling web services to fetch the data's. So i will get the data in xml format. For example if i wants to create a new person , in that page i will show the fields like Country , State all this fields values are coming from webservices only. So sending this XML values to JSP and parsing there i found some what difficult. If i am using JAXB also same , i needs to send the JAXBObject to my jsp page and i need to populate values there. I hope it is clear.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

You should do all the XML parsing in the servlet, capture the data in normal Java objects, and send those to the JSP. In the JSP, the EL and JSTL can be easily used to consume this data.

The best way to always approach this is to make the servlet do all the hard work of massaging the data into a structure that makes it easy for the JSP to do its job. In other words, keep the JSPs as stupid as possible.
vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 81

Bear Bibeault is right. It disturbs MVC architecture if you put too much code in JSP. JSP should be view component
Dilip Ganesh
Greenhorn

Joined: Sep 30, 2011
Posts: 24
Thank you so much for your suggestions
Dilip Ganesh
Greenhorn

Joined: Sep 30, 2011
Posts: 24
It should not be difficult. So instead of trying to find some other weird way of doing it -- which is most likely to be even more difficult because it's not natural -- makes no sense at all.

The best approach would be to try to find out what you are doing wrong that makes it difficult.

So what difficulties did you run into?


I agree to your approach. Just wants to share with you in gridsphere portal we can set the form element values from the portlet itself.

i.e Gridsphere portal having their own Custom Tag Library , so that we can access those tag library classes inside the portlet class and we can set the values for those .

So i wants to know whether it is possible in servlets or not.
 
 
subject: Populating values for form input elements using servlet