I have a jsp that is being used by multiple user groups. The requirement is that each User group wants a customized look and feel when they access the page (with a distinguishing parameter). We are proposing to allow the Users to dump the html that they need in a database table and the jsp will determine the User group and they display the corresponding html. Any pointers on how this can be done?
Example: if User group 1 access the url abc.com/xyz?param=aaa, then the jsp should display the html that is stored in the database corresponding to UserGroup1. similarly, abc.com/xyz?param=bbb should render the html stored for UserGroup2.
html for Group 1:
<html>hello, user 1 </html>
html for Group 2:
<html>hello, user 2 </html>
How does my JSP get this html code from Servlets or any other classes?
Any JSF 2.0 suggestions are also welcome.
The above example code might sound simple, but in reality the entire layout, images, borders, tables, content will be different
distinguish between users through the use of session and manage it by its API
IMO, i would not store html in the DB. It is not where it belongs.
What you can do (in JSF 2.0) is create a 'template' page that contains basic things that you reuse on each page...header,body, footer, css, js, etc.
On this 'template' page, you can use the <ui:insert name="body"> tag to define places that each page will define.
On your pages, you use the <ui:composition template="whateverPage.xhtml"/> to define your template. Then you can insert the code you want based on whatever params using <ui:define name="body">
JSF 2 Templating with Facelets
instead of saving entire html which is not recommended as phanneman says,
save a css or css snippets . for example save in your db, the image paths for each user, color, etc in the db for each user.
this might help by retriving the specific data for each userGroup.
Related
I want to store html components of my website in the database in order to let the user choose from a variety of components each time
for example :
one page styled html page with a navbar and about section that could be changed and other stuff , it's layout could contain the following :
<div id="nav-holder">
<!-- Nav html goes here -->
</div>
<div id="about-holder">
<!-- about section html goes here -->
</div>
<!-- other html stuff -->
My db now is structured to hold the template with it's possible components for each section , and is storing a 'text' in it's html column , and I am adding all my styling and scripting to one sheet and js file that is loaded for the whole layout.
Is there any best practice to store and render those components in my db ?
Edit :
My main purpose is to create a website generator with some customization , providing a set of templates that the user chooses and within one template he can customize his template by choosing different components (navs,about sections , ... )
Also I will grab the data from some place and fill it into those templates The user will not be able to modify the data here , it's ready already so there is no need to give the user the ability to modify the data that would be filled in the document
Is there any best practice to store and render those components in my
db ?
Yes, don't! For several reasons, the primary one being that you use your database to persistently store variables related to models. Not html. The place for your html is in your views, the place to make choices as to which html to show is in your controllers.
Other reasons include that reading your html from a database will slow down your apps responsiveness and Rails tends to make text from a database html safe, meaning it will not automatically behave as html. This is a security precaution as a very common attack is to insert 'bad' code into your database which then gets run when you recover it and supply it to an unsuspecting user.
Use partials. Reference section 3.4 of this Rails Guide
Save the users choices of components in the database. If he chooses navbar_23, you store that 9 character string in the database and on request, your template serves him the partial named _navbar_23.html.erb from your views folder.
For example, in your views folder, create a subfolder views/navbars, inside that place your variants of navbars. Partials start with an underscore and end with .html.erb
In your model, store the users choice of navbar in say user.navbar. Just the name, not the starting underscore or .html.erb
In your template;
render partial: "views/navbars/" + user.navbar
Rails will automagically add the underscore and .html.erb when it looks for the file.
I just want to automate a web application, where that application parses the HTML page and pulls all the HTML Tags inner text based on some condition like if we have a tag called Span Example has given whose class="spanclass_1"
This is span tag...
which has particular class id. so that app parses and pulls that span into it.
And here the main pain area is, I should not use the developer code to automate that same parsing the HTML.
I want to automate that parsing done correctly, simply by using the parsed data which is shown in UI.
Any help, would be great.
Appreciating your time reading this.
(Note span tag is not shown)
Thanks buddies.
not enough details.
is this html page just a file in local filesystem on it is internet webpage?
do u have access to pages? can u modify it ? if answer yes, that just add javascript to page which will extract data and post to server.
if answer not, than it depends on language u use to programm.
Find good framework to parse html. load page parse it and extract data. Several situation can be there.
Worse scenario - page generated on client side using js.
Best scenario - page is in xhtml mode( u are lucky. any xml parser will help to build dom and extract data)
So so - page is simple html format (try several html parser to find most suitable for u)
I have several HTML pages and some of the content is same for all the pages. Is there a way to put the content into a single file and include it in all the HTML Pages?
Lets say that the common data is in HTML format.
Yes you can use iframes for this purpose.
Design your master page in .html format and use it with iframe tag
<iframe src="MasterPage.html"></iframe>
Refer following link:
http://reference.sitepoint.com/html/iframe
I think what you are looking for is a templating solution.
You can do it in jsp as follows
by using two ways
<jsp:include page="reuse.html" />
or
<#include file="reuse.html">
Have a look at this question What is the difference between <jsp:include page = ... > and <%# include file = ... >?
You can do this in three places:
At build/publication time — you generate HTML documents from your data sources and then publish static files. This option works for everybody, but can make the build times rather long for very large sites. I use ttree for this.
At run time, on the server — this works in much the same way as the previous option, but is done on the server and on demand (i.e. when a page is requested). Template-toolkit is also an option here, but here are many many others, including Django templates and Smarty.
At run time, on the client — this involves pulling the content together using frames or JavaScript. It is unfriendly to search engines and will break bookmarking unless you are very careful. I don't recomment it.
One thing you can try is using PHP.
for example if all pages have a common header, create a new document with the name of header.php and place the contents of the header div inside. Every other page you want the header to appear just call it by using :
<?php include_once("header.php");?>
Hope this helps
The best way to do this is at run time.
This means using PHP, ASP, JSP or another server-side scripting solution to join your pages together on demand when sending them to the client.
In PHP, this can be achieved with the following:
<?php
include_once("head.php");
?>
<!-- some body content -->
<?php
include_once("foot.php");
?>
Managing your header, footer and content all separately makes it very easy to update your design without having to edit many files.
It is not recommended to do this client-side with frames/iframes, as this is very unfriendly to search engines and can slow down your server as several HTTP requests must be initiated.
I need to display an image in an S-Control is SFDC. I would like to be able to reference a static resource like <apex:image url="{!$Resource.TestImage}" />, but that only works in VisualForce pages and I have to modify and existing S-Control (switching to VF is not an option).
What's the best way to accomplish this, so frustrated with the general lack of documentation and hackishness of SFDC development.
Thanks all
You can upload your image to Documents tab and later use normal <img> tag to display it on S-Controls, Visualforce pages and email templates (last one - if this will be an "externally available image"). The generated URL to view it will look somewhat like
https://c.na7.content.force.com/servlet/servlet.FileDownload?file=015A0000001IFxZ
(my test org sits at na7.salesforce.com instance and the last part is gnerated object's ID)
I want to create an html page which contains a text box. When I am given input and the Enter key is pressed, I want it to go to another html page and display the typed keyword.
How can I do this?
I think you need to use a server-side scripting language to facilitate the manipulation of the inputted data on the form, so that it gets "saved" and displayed in the other html page. I suggest you try reading about PHP, and then turn to handling information in Web Forms...just a thought!
You can use Javascript for that. Check this Tutorial : How do I pass variables between two pages? (GET method)