• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Binding Tags on Response to UI

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I saw in few cases,

List<String> map = new ArrayList<>();
map.add("Count : <b>"+count +"</b>");

some of the web-application embed or append and send back the response to the UI with HTML tags..

Using angular web application

when i checked with a front-end developer he says sometimes it is bit to handle so sending as tags is the right approach

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?

Thanks
 
Marshal
Posts: 25456
65
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are reading a document which uses the variable name "map" for a List, you certainly shouldn't trust that document to inform you about "best practices".
 
Sheriff
Posts: 7062
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Johnny Joseph
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 15527
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johnny Joseph wrote:
List<String> map = new ArrayList<>();
map.add("Count : <b>"+count +"</b>");


I can't think of ANY instance where the above code on the server side would be considered "best practice", unless you're some kind of sado-masochist who thrives on pain and suffering.
 
Junilu Lacar
Sheriff
Posts: 15527
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

2b. Create a structured text-based representation of the Model/ViewModel, usually as XML or JSON, and send that as the response to the client. The XML or JSON can then be transformed and/or rendered on the client side using any combination of technologies like HTML+CSS+JavaScript, XML stylesheets, and client-side templating engines which these days are usually JavaScript frameworks like Angular and React, among others.
 
Johnny Joseph
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's take this example

#1 Client has several document format in HTML format with signature and other additional details has to be filled up dynamically

#2 - We need to save all the different format of HTML to the database. i.e Template Design which is in back-end

#3 - Now we would append all the details needed for the template

So in this case, we might need to append HTML tags as part of the response to send it...

Do you have any suggestion to overcome this?
 
Knute Snortum
Sheriff
Posts: 7062
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a feeling this is somewhere along the lines of "Rewrite you backend and restructure your database," so maybe not something you're going to do today.  Maybe just keep it in mind the next time.

Just curious: does the user actually write documents in HTML?  What if they want to send out an Office document or some other format?
 
Saloon Keeper
Posts: 21981
150
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Marshal
Posts: 25456
65
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Johnny Joseph
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Please advise.
 
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic