Johnny Joseph wrote:Can someone please let me know in which use cases we need to use HTML tags as response and in which case we should not use it?
What is the best standard practice?
Are you saying that a server (backend) program is sending HTML tags in its response, and asking if that is a good idea? I'd say no, because the server program should be agnostic in terms of the frontend UI.
All things are lawful, but not all things are profitable.
posted 1 week ago
Yes, the server program should be agnostic. But in several times i come across in different projects with such practices of having HTML tags in back-end code.ow
Please let me know
Johnny Joseph wrote:What is the best standard practice?
Separate data from formatting. By doing this: list.add("Count : <b>" + count + "</b>") you are inappropriately combining the two.
The principle of separating data from formatting generally leads to this:
1. Use a Model of ViewModel to represent data/information and relationships between different sets of data
2. Create a view for the information represented by the Model/ViewModel:
2a. Use a templating engine on the server side to present data in the desired format. This generates HTML on the server side which is sent to the client as a response.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
Yes, I have had to deal with documents/databases that contained fields with embedded HTML. This was stuff like legal docs and the like where lawyers could never be satisfied with "Is the client dead Y/N?", and felt obliged to put in stuff like "Client is deceased for the purposes of S.R. 237 except when lunar occultation ipso lardo renders in the form of particulate matter as described in Subsection C pending arbitration."
I've also had to take RTF formatted documents and convert them to HTML for web rendering as fields on an HTML page or form.
When at all possible, one should not generate or otherwise render HTML in the Controller code, But sometimes, it's necessary. Ipso Lardo.
"privilege" comes from the Latin words for "private" and "law" (legal) and dates to feudal times. To "claim privilege" meant that you were above the laws that applied to the common people.
Tim Holloway wrote:When at all possible, one should not generate or otherwise render HTML in the Controller code, But sometimes, it's necessary. Ipso Lardo.
In the case posted, I envision the following scenario: a web application was produced which includes the "count" of something. A user interface was designed by professional designers and CSS was carefully crafted to make it consistent. Later one of the vice-presidents demanded that the count should appear in bold if it exceeded 1000 and the client's bills were more than 90 days past due. There were no CSS elements which supported this possibility. And so the posted workaround was implemented. Fortunately the code which produced the page didn't escape HTML in the "count" field.
posted 1 week ago
Which Tim explained is the best example too....
We need to discuss on how to avoid these kinds of insertions from back-end.
#1, What are the alternate approaches to overcome this problem?
#2, One more case is one would have a generic report, however in one of the use case certain values needs to be bolded. In that case, front-end will not know about this. It would be complex in the front-end side to deal with it. Forwarding several variables from back-end for special treatment would be messy.
Destroy anything that stands in your way. Except this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book