Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8814615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:10:20+00:00 2026-06-14T04:10:20+00:00

I have been looking with no success to see if I can dynamically apply

  • 0

I have been looking with no success to see if I can dynamically apply a css style to JSF component or div using javascript. Is this possible.

This is pseudo code

<div style="myJSStyleFunction("#{myBean.value}")"> stuff </div>

And the function would return something like “position:relative;left:25px;”

I’ve had no luck and maybe it can’t be done but would like a second opinion.

Edit:


I’m trying to see if I can keep a separation / reduce the coupling between the presentation/view and the model/controller. This is for indenting commenting or product reviews (to nest replies to comments or reviews). The most I really want to track is an integer on how deep a reply is. First level = 0 second level = 1, and so on. So a comment or product review would be 0 deep, a reply to the comment or review would be 1 and so on.

Then in the EL I wanted to call a javascript function and do something like

<script>
    myJSStyleFunction(depth){
        if(depth<=5){
            var nest=20*depth;
            var style="position:relative;left:" + nest + "px;";
            return style;
        }
    }
</script>

And then then say for a third level comment (a reply to a reply) it would look like this:

<div style="position:relative;left:40px;"> stuff </div>

where

#{myBean.value}

evaluates to 2

I suspect like Daniel says I’ll have to tightly couple the view but I’d rather not have to. I’d think there has to be a way. But maybe not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:10:21+00:00Added an answer on June 14, 2026 at 4:10 am

    I decided to skip the javascript approach and settled on a simpler and I think cleaner method to create the dynamic css classes for my situation. I already capture/calculate the depth value for each comment when it is entered. So I am just returning that value in EL and concatenating it to a ‘base name’ for the css class like so:

    <div class="indent_#{(comment.commentDepth le 5) ? comment.commentDepth : 5}" >
        comment comment blah blah blah
    </div>
    

    “indent_” is the base name for the css class. So for a 0 level comment it will have a class="indent_0". A reply to that comment will have class="indent_1".

    I use the ternary so that if there are lot of replies under a given comment it doesn’t indent right off the right hand side of the page. Even though you can keep going deeper, it will only indent up to 5 levels.

    For my case at the moment, this is a simpler and cleaner method of adding some dynamically generated css class names. Right now I have to define 6 classes for this in the css file, but perhaps I’ll figure out how to nest the boxes but it isn’t a priority this works just fine for me for now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking at this for a while and can't see where the
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking into backbone.js and I can't seem to figure out how
I have been looking on how to consume a webmethod using the $.ajax call
I have been looking at making the switch from SQL TableAdapters to Linq using
I have been looking for a way to do the following action using the
I have been looking at this for several days now with no success. I
I have been looking online without success for something that does the following. I
I have been looking all over MSDN and can't find a reason why Thread
I have been looking around for a visualization framework that would aid graph visualization

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.