Re: JSTL - Following MVC
Christine Mayer wrote:
Well, but the problem described is more specific - There is a String,
lets stay "This is my nice little String".
Now the user can search for a word, lets say "little".
In this case, I must call a function
public formatMyString(String myString, searchstring) {
.......
return formatedString
}
Consider spelling that variable "formattedString".
now currently, in the jsp, this function gets called like this
formatMyString("This is my nice little String", "little" )
which then will return on the view: "This is my nice <strong>little</
strong> String".
I don't think you could do something like that in JSF, could you??
Sure, and that way you'd avoid having that Java code appear in your JSP.
You could also do it with a custom tag.
It is common wisdom that avoiding Java scriptlet in a JSP is a best practice.
You asked about MVC; that implies moving the logic out of the JSP so that it
concerns itself only with the view.
What you do instead is submit the values to a controller servlet that forwards
the text to a validation or transformation method and adds the markup in
question. Use EL (expression language) to recover the altered value.
There are a number of idioms and hacks to get the search string and the search
term into parameters in the JSP that are processed on the back end.
Presumably you've solved that part of the problem.
The method you are using can be called on the back end, and that tends to make
better separation of concerns per your subject line.
--
Lew