> Well, but the problem described is more specific - There is a String,
> lets stay "This is my nice little String".
[quoted text clipped - 4 lines]
> 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" )
[quoted text clipped - 3 lines]
>
> 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.

Signature
Lew
Christine Mayer - 14 Sep 2007 07:13 GMT
Lew schrieb:
>> I don't think you could do something like that in JSF, could you??
Well, I also don't think we would switch to JSF so fast (political...)
> You could also do it with a custom tag.
No idea how to do a custom tag, I guess that must be very complicated.
> 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.
I know, I know! Thats why I posted my question in the first place!
> 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.
Well, of course it can be called in the backend - but then I have to
save it in an additional attribute, or in an additional model,
and my question was if I should do it like that:
a) View Model and Data Model total separated, but mapping from one model
to the other necessary
Model MyDataModel {
private String myStringData;
[...]
public String getMyStringData(){
[...]
}
public void setMyStringData(String s) {
[...]
}
[...]
}
Model myViewModel {
[...]
private String myStringView;
public String getMyStringView(){
[...]
}
public void setMyStringView([...]
}
[...]
}
Controller MyController{
[...]
Model myDataModel = getMyDataModel();
Model myViewModel = new ViewModel();
for(object: myDataModel ){ // Assume my Model is somewhat more complex
[...]
String dataString = object.getMyStringData;
String viewString = convertMyString(dataString);
myViewModel.setMyStringView(viewString );
}
}
b) Only one model, no conversion necessary, but twice as much attributes
in one class, which are similar to each other.
Model MyModel {
private String myStringData;
private String myStringView;
[...]
public String getMyStringData(){
[...]
}
public void setMyStringData(String s) {
[...]
setMyStringView(s);
}
public String getMyStringView(){
[...]
}
public void setMyStringView(String s)
convertMyString(s);
[...]
}
[...]
}
}
or c) Only one model, only one attribute each, String gets converted
just in time (As the data will be re-retrieved with each re-request,
this is not really a problem)
Model MyModel {
private String myStringData;
[...]
public String getMyStringData(){
[...]
}
public void setMyStringData(String s) {
[...]
}
public String getMyStringView(){
return convertMyString(getMyStringData() );
[...]
}
[...]
}
Thanks in advance!