• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

get form object in jsp

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends...

i have to develop a new web application in struts.
i am planning to write some methods in form class that return dynamic HTML text for writing in JSP.

is it possible to access form object from JSP file and invoke methods in form class?

i am new to struts and don't know is it the correct way for that...

could any one please solve my issue?....
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jomy George,

did you solve your problem? If so how and if not could you attach your code

see you
 
Jomy George
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no i couldnt fins a solution till
i can access a property from my from class in jsp page as

<bean:write name="LoginForm" property="userName"/>

but can i access a method similar way?
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are no custom tags in struts to let you call a method in your form that I know of. You can write a scriptlet to do it though (although that should be avoided). Why do you need to call a method in your form class to "return dynamic HTML text"? It sounds likely that you have "View" code written in your "Model" class which is something you should usually avoid in an MVC framework.
 
Jomy George
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Tom Rispoli for your reply

i a beginner in struts and don't know much about it.
from books i learned that form class is a part of view ( form and corresponding JSP are comes under view module ).
that's why i tried to return an HTML from form class. (hope this not violate MCV)
i am not using this method in model class where my business logic comes.

i can access variable in form class in JSP page and can use it to create HTML for showing in browser. i thought writting a method that return ready to render HTML and simply use it in JSP.

hope you can clarify my doubt...
thanks once again



 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct, both JSP and and form are part of the view layer, however, the intent of the form is normally to serve as a conduit to move data between the MVC layers. Putting HTML into it is normally inappropriate as this is what JSPs are designed to do. It is easier to maintain html in a JSP than it is in a java class. If you have some repetitive HTML work to do, and there is no custom tag in struts for it, you may want to write your own custom tag. I don't know the intent of the html you are writting, but I think its likely that you want to put it in your JSP rather than in your form.
 
Adam Miller
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jomy,

now the sense of Struts is to separate the different concerns. Please see also http://struts.apache.org/primer.html#mvc.
I don't know if it makes sense to generate HTML inside a java class instead of producing it in a JSP. As Tom wrote
it might be uncommon to generate HTML as it might be difficult to maintain such HTML. Of course it is possible to write
a java class generating HTML . So you can test it. Please write a Servlet class which will produce HTML as a result.
To make it more interesting just generate a huge HTML page where you write into some variables let us say using StringBuffer
or StringBuilder. Then try to do a complete redesign of that web page changing the generator class. Then you might
recognize that it would be better to put it all into a JSP page and all the rest into a model. The sense of MVC is to disjoin
the three concerns namely model, view, controller.

If you like you can present your code so that people can speak about it and you could learn On the other hand there are
lots of different example codes using struts.
 
A wop bop a lu bop a womp bam boom! Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic