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.
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
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.
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.
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
a bit of art, as a gift, that will fit in a stocking