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

  • SEARCH
  • Home
  • 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 3637462
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:09:41+00:00 2026-05-19T01:09:41+00:00

We use facelets to create some custom ajaxy components. One of the behaviours we

  • 0

We use facelets to create some custom ajaxy components. One of the behaviours we would like to mimic from the default components is that an id is optional, and an id is generated if it is not passed. I can already do it like this:

<ui:composition ...>
  <div class="myComponent" id="#{jsfSupport.generateId(id)}">
     ...
  </div>
</ui:composition>

I use JBoss el to call a support method (could use el functions as well):

public class JsfSupport {

  public String generateId(String id) {

    if (id==null || "".equals(id){
  return FacesContext.getCurrentInstance().getViewRoot().createUniqueId();
    }
    return id;
  }

}

The problem is that if I need that id somewhere in my javascript code in the component, I need to retrieve it again. So I thought I could do the following:

<ui:composition ...>
  <c:set var="id" value="#{jsfSupport.generateId(id)}" />
  <div class="myComponent" id="#{id}">
     ...
  </div>
  <script type="text/javascript">
    document.getElementById('#{id}');
  </script>
</ui:composition>

But that doesn’t work. The id gets regenerated anyway and I get two different ones.
Any ideas on what would be the ideal way to do this?

  • 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-05-19T01:09:42+00:00Added an answer on May 19, 2026 at 1:09 am

    <c:set> in Facelets means aliasing, not an assignment like in JSP. So every use of #{id} is translated into a separate call to #{jsfSupport.generateId(id)}, which results in problems you describe.

    You could write your own version of <c:set> tag which would evaluate the passed expression only once, and save the returned value:

    public class SetOnceHandler extends TagHandler
    {
        private TagAttribute var;
        private TagAttribute value;
    
        public SetOnceHandler(TagConfig cfg) 
        {
            super(cfg);
            value = getRequiredAttribute("value");
            var = getRequiredAttribute("var");
        }
    
        public void apply(FaceletContext ctx, UIComponent parent) 
        {
            ctx.setAttribute(var.getValue(ctx), value.getObject(ctx));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use JavaScript to manipulate hidden input fields in a JSF/Facelets
(please excuse that I didn't use aliases). I would like my query output to
We use a data acquisition card to take readings from a device that increases
How can I use session for facelets ? What's the syntax...? I would put
I have created a custom facelets component and I need to set some value
'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move
I use a stream reader to import some data and at the moment I
I want to create a component which can be used like: <mc:chart data=#{bean.data} width=200
Facelets uses the jsfc attribute to convert HTML elements to their associated JSF components.
I'm trying to create a composite component for use in my Seam application, and

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.