You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by FaRHaN <fa...@ymail.com> on 2009/07/22 13:07:05 UTC

Save CSS/StyleSheet in Database ?

Hi,

Is there any way to store CSS settings and classes into a database. I have a css file describing styles for whole website. 
I want to give user an option, to modify styles (background color, font, table header font, etc.) of thier own choices (at run-time). When user selects from the given options and hit save, then these values store in the database, so that when user visits the website next time then customized styles (theme) should be displayed on the web pages rather than default styles.
I know  this can be done by using cookies (through javascript) but the problem arises when user visits the website after deleting private data of browser. In this way, again default styles applies to all web pages.

Is there any way to make css file dynamic (using variables in css file), or to save css classes (styles) into database ?

Thanks,
Farhan.



      

Re: Save CSS/StyleSheet in Database ?

Posted by FaRHaN <fa...@ymail.com>.
It means there will be a separate CSS file for each user. This will impose heavy load on the application, and where is database involved in that case, as i want to save and load css styles from database ?
Is there any other way to do that ?
Can we make CSS file dynamic e.g. body{background: {$color};} and then modify that color variable in our javacode (like inPHP) ?



________________________________
From: Russell Simpkins <ru...@hotmail.com>
To: users@wicket.apache.org
Sent: Wednesday, July 22, 2009 6:23:09 PM
Subject: RE: Save CSS/StyleSheet in Database ?


I have not done this myself, but I think you might get what you want using the SimpleAttributeModifier. Say you were doing a css style:
<link rel="stylesheet" type="text/css" href="css/standard.css" wicket:id="userStyles:/>
Then in your javacode you can have:
userCss.add(new SimpleAttributeModifier("href", "css/" + LOGGEDINUSER.getUserId() + ".css"));
You could always do something similar in javascript with cookies.
Russ

> Date: Wed, 22 Jul 2009 05:12:45 -0700
> From: farhan.bajwa@ymail.com
> Subject: Re: Save CSS/StyleSheet in Database ?
> To: users@wicket.apache.org
> 
> Thanks for quick response.
> Obviously, styles can be loaded from database after Login. But i want to make a separate css file and dont want ot add it in the java code, for sake of simplicity. 
> 
> Is there any way to store css styles directly from css file for a specific user, and then load styles directly to css file after user Login ?
> 
> Or can we make css file dynamic by introducing variables in it (like in PHP) ?
> 
> Thanks...
> 
> 
> ________________________________
> From: Mathias Nilsson <wi...@gmail.com>
> To: users@wicket.apache.org
> Sent: Wednesday, July 22, 2009 4:59:53 PM
> Subject: Re: Save CSS/StyleSheet in Database ?
> 
> 
> You would probably have to use cookies to save which style the users would
> have. There is no way knowing this without login or cookie.
> 
> There are probably a better way of doing this but if you save style and
> classes in a database like this
> 
> *{ font-family: verdana; } // a row in the database
> a{ color: red; } // a row in the database
> 
> you could implement the IHeaderContributor and override the renderHead
> 
> public void renderHead(IHeaderResponse response) {
>   StringBuffer buf = new StringBuffer();
>   buf.append( "<style type=\"text/css\">" ); 
>   buf.append( "*{ font-size: 9px; }" );
>   buf.append( "</style>" );
>   response.renderString(buf);
> }
> 
> of couse you should the get it from a service or directly from a dao.
> 
> public void renderHead(IHeaderResponse response) {
>    BradningService service = getBrandingService(); // get this using
> @SpringBean or whatever
>    List<String> styles = service.getStyles( user ); // get the style for a
> user
>    iterate here and add the style
> 
> }
> 
> 
> -- 
> View this message in context: http://www.nabble.com/Save-CSS-StyleSheet-in-Database---tp24604324p24604928.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
>      

_________________________________________________________________
Windows Live™ SkyDrive™: Store, access, and share your photos. See how.
http://windowslive.com/Online/SkyDrive?ocid=TXT_TAGLM_WL_CS_SD_photos_072009


      

RE: Save CSS/StyleSheet in Database ?

Posted by Russell Simpkins <ru...@hotmail.com>.
I have not done this myself, but I think you might get what you want using the SimpleAttributeModifier. Say you were doing a css style:
<link rel="stylesheet" type="text/css" href="css/standard.css" wicket:id="userStyles:/>
Then in your javacode you can have:
userCss.add(new SimpleAttributeModifier("href", "css/" + LOGGEDINUSER.getUserId() + ".css"));
You could always do something similar in javascript with cookies.
Russ

> Date: Wed, 22 Jul 2009 05:12:45 -0700
> From: farhan.bajwa@ymail.com
> Subject: Re: Save CSS/StyleSheet in Database ?
> To: users@wicket.apache.org
> 
> Thanks for quick response.
> Obviously, styles can be loaded from database after Login. But i want to make a separate css file and dont want ot add it in the java code, for sake of simplicity. 
> 
> Is there any way to store css styles directly from css file for a specific user, and then load styles directly to css file after user Login ?
> 
> Or can we make css file dynamic by introducing variables in it (like in PHP) ?
> 
> Thanks...
> 
> 
> ________________________________
> From: Mathias Nilsson <wi...@gmail.com>
> To: users@wicket.apache.org
> Sent: Wednesday, July 22, 2009 4:59:53 PM
> Subject: Re: Save CSS/StyleSheet in Database ?
> 
> 
> You would probably have to use cookies to save which style the users would
> have. There is no way knowing this without login or cookie.
> 
> There are probably a better way of doing this but if you save style and
> classes in a database like this
> 
> *{ font-family: verdana; } // a row in the database
> a{ color: red; } // a row in the database
> 
> you could implement the IHeaderContributor and override the renderHead
> 
> public void renderHead(IHeaderResponse response) {
>   StringBuffer buf = new StringBuffer();
>   buf.append( "<style type=\"text/css\">" ); 
>   buf.append( "*{ font-size: 9px; }" );
>   buf.append( "</style>" );
>   response.renderString(buf);
> }
> 
> of couse you should the get it from a service or directly from a dao.
> 
> public void renderHead(IHeaderResponse response) {
>    BradningService service = getBrandingService(); // get this using
> @SpringBean or whatever
>    List<String> styles = service.getStyles( user ); // get the style for a
> user
>    iterate here and add the style
> 
> }
> 
> 
> -- 
> View this message in context: http://www.nabble.com/Save-CSS-StyleSheet-in-Database---tp24604324p24604928.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
>       

_________________________________________________________________
Windows Live™ SkyDrive™: Store, access, and share your photos. See how.
http://windowslive.com/Online/SkyDrive?ocid=TXT_TAGLM_WL_CS_SD_photos_072009

Re: Save CSS/StyleSheet in Database ?

Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
Hi Farhan,

> Can you please send me the sample codes of your implementation for Images ?
>
> I also want dynamic images to be displayed on my web page.
>   
I tried to condense what I did into an email but that grew too big.  
I've put up the important classes onto the Wicket Wiki here: 
http://cwiki.apache.org/confluence/display/WICKET/How+to+Stamp+an+Image+Template+with+Context+Specific+Details.

You can see that is much more limited than what you are talking about 
implementing but perhaps it can be a place to start from.

Regards,

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Save CSS/StyleSheet in Database ?

Posted by FaRHaN <fa...@ymail.com>.
Can you please send me the sample codes of your implementation for Images ?

I also want dynamic images to be displayed on my web page.

Thanks,
Farhan


________________________________
From: Michael O'Cleirigh <mi...@rivulet.ca>
To: users@wicket.apache.org
Sent: Wednesday, July 22, 2009 8:04:00 PM
Subject: Re: Save CSS/StyleSheet in Database ?

Hi Farhan,

You should create an  IRequestTargetUrlCodingStrategy implementation to 
serve the CSS from the database.

It should work to mount the strategy on something like 
'/custom-user-css' and then user the rest of the path as the options for 
say  the user and version of the css to load.  The version number may be 
needed to get around browser caching of the CSS if changes are made.  
You get look at the other implementations to see how they do this but 
yours will be slightly different since you are serving CSS not Pages.

You can then add in the CSS resource link to the pages that need it only 
customizing the user parameter part of the url.

I've done something similar for generating user specific images (custom 
images stamped with user specific details) so I know it will work.

Regards,

Mike

> Thanks for quick response.
> Obviously, styles can be loaded from database after Login. But i want to make a separate css file and dont want ot add it in the java code, for sake of simplicity. 
>
> Is there any way to store css styles directly from css file for a specific user, and then load styles directly to css file after user Login ?
>
> Or can we make css file dynamic by introducing variables in it (like in PHP) ?
>
> Thanks...
>
>
> ________________________________
> From: Mathias Nilsson <wi...@gmail.com>
> To: users@wicket.apache.org
> Sent: Wednesday, July 22, 2009 4:59:53 PM
> Subject: Re: Save CSS/StyleSheet in Database ?
>
>
> You would probably have to use cookies to save which style the users would
> have. There is no way knowing this without login or cookie.
>
> There are probably a better way of doing this but if you save style and
> classes in a database like this
>
> *{ font-family: verdana; } // a row in the database
> a{ color: red; } // a row in the database
>
> you could implement the IHeaderContributor and override the renderHead
>
> public void renderHead(IHeaderResponse response) {
>   StringBuffer buf = new StringBuffer();
>   buf.append( "<style type=\"text/css\">" ); 
>   buf.append( "*{ font-size: 9px; }" );
>   buf.append( "</style>" );
>   response.renderString(buf);
> }
>
> of couse you should the get it from a service or directly from a dao.
>
> public void renderHead(IHeaderResponse response) {
>    BradningService service = getBrandingService(); // get this using
> @SpringBean or whatever
>    List<String> styles = service.getStyles( user ); // get the style for a
> user
>    iterate here and add the style
>
> }
>
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


      

Re: Save CSS/StyleSheet in Database ?

Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
Hi Farhan,

You should create an  IRequestTargetUrlCodingStrategy implementation to 
serve the CSS from the database.

It should work to mount the strategy on something like 
'/custom-user-css' and then user the rest of the path as the options for 
say  the user and version of the css to load.  The version number may be 
needed to get around browser caching of the CSS if changes are made.  
You get look at the other implementations to see how they do this but 
yours will be slightly different since you are serving CSS not Pages.

You can then add in the CSS resource link to the pages that need it only 
customizing the user parameter part of the url.

I've done something similar for generating user specific images (custom 
images stamped with user specific details) so I know it will work.

Regards,

Mike

> Thanks for quick response.
> Obviously, styles can be loaded from database after Login. But i want to make a separate css file and dont want ot add it in the java code, for sake of simplicity. 
>
> Is there any way to store css styles directly from css file for a specific user, and then load styles directly to css file after user Login ?
>
> Or can we make css file dynamic by introducing variables in it (like in PHP) ?
>
> Thanks...
>
>
> ________________________________
> From: Mathias Nilsson <wi...@gmail.com>
> To: users@wicket.apache.org
> Sent: Wednesday, July 22, 2009 4:59:53 PM
> Subject: Re: Save CSS/StyleSheet in Database ?
>
>
> You would probably have to use cookies to save which style the users would
> have. There is no way knowing this without login or cookie.
>
> There are probably a better way of doing this but if you save style and
> classes in a database like this
>
> *{ font-family: verdana; } // a row in the database
> a{ color: red; } // a row in the database
>
> you could implement the IHeaderContributor and override the renderHead
>
> public void renderHead(IHeaderResponse response) {
>   StringBuffer buf = new StringBuffer();
>   buf.append( "<style type=\"text/css\">" ); 
>   buf.append( "*{ font-size: 9px; }" );
>   buf.append( "</style>" );
>   response.renderString(buf);
> }
>
> of couse you should the get it from a service or directly from a dao.
>
> public void renderHead(IHeaderResponse response) {
>    BradningService service = getBrandingService(); // get this using
> @SpringBean or whatever
>    List<String> styles = service.getStyles( user ); // get the style for a
> user
>    iterate here and add the style
>
> }
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Save CSS/StyleSheet in Database ?

Posted by FaRHaN <fa...@ymail.com>.
Thanks for quick response.
Obviously, styles can be loaded from database after Login. But i want to make a separate css file and dont want ot add it in the java code, for sake of simplicity. 

Is there any way to store css styles directly from css file for a specific user, and then load styles directly to css file after user Login ?

Or can we make css file dynamic by introducing variables in it (like in PHP) ?

Thanks...


________________________________
From: Mathias Nilsson <wi...@gmail.com>
To: users@wicket.apache.org
Sent: Wednesday, July 22, 2009 4:59:53 PM
Subject: Re: Save CSS/StyleSheet in Database ?


You would probably have to use cookies to save which style the users would
have. There is no way knowing this without login or cookie.

There are probably a better way of doing this but if you save style and
classes in a database like this

*{ font-family: verdana; } // a row in the database
a{ color: red; } // a row in the database

you could implement the IHeaderContributor and override the renderHead

public void renderHead(IHeaderResponse response) {
  StringBuffer buf = new StringBuffer();
  buf.append( "<style type=\"text/css\">" ); 
  buf.append( "*{ font-size: 9px; }" );
  buf.append( "</style>" );
  response.renderString(buf);
}

of couse you should the get it from a service or directly from a dao.

public void renderHead(IHeaderResponse response) {
   BradningService service = getBrandingService(); // get this using
@SpringBean or whatever
   List<String> styles = service.getStyles( user ); // get the style for a
user
   iterate here and add the style

}


-- 
View this message in context: http://www.nabble.com/Save-CSS-StyleSheet-in-Database---tp24604324p24604928.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


      

Re: Save CSS/StyleSheet in Database ?

Posted by Mathias Nilsson <wi...@gmail.com>.
You would probably have to use cookies to save which style the users would
have. There is no way knowing this without login or cookie.

There are probably a better way of doing this but if you save style and
classes in a database like this

*{ font-family: verdana; } // a row in the database
a{ color: red; } // a row in the database

you could implement the IHeaderContributor and override the renderHead

public void renderHead(IHeaderResponse response) {
  StringBuffer buf = new StringBuffer();
  buf.append( "<style type=\"text/css\">" ); 
  buf.append( "*{ font-size: 9px; }" );
  buf.append( "</style>" );
  response.renderString(buf);
}

of couse you should the get it from a service or directly from a dao.

public void renderHead(IHeaderResponse response) {
   BradningService service = getBrandingService(); // get this using
@SpringBean or whatever
   List<String> styles = service.getStyles( user ); // get the style for a
user
   iterate here and add the style

}


-- 
View this message in context: http://www.nabble.com/Save-CSS-StyleSheet-in-Database---tp24604324p24604928.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org