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 6668457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:02:38+00:00 2026-05-26T03:02:38+00:00

How to update the style of a JSF component at runtime, I must clarify

  • 0

How to update the style of a JSF component at runtime, I must clarify that I want to change the position of the component and in some cases hide it.

<ui:define name="reverso" id="reverso" >
       <!-- Logo Estado Próspero -->
       <p:graphicImage value="./resources/oficiales/prospero.png" style="width: 90px; height: 50px;position: relative; left: 150px" />
       <h:form id="dataRfc">
            <h:outputText id="display_rfc" rendered="true" value="#{IDWizard.rfc}" binding="#{IDWizard.outRfc}" style="color: #333333;text-align:center;margin-top: 30px" />
       </h:form>
</ui:define>

public void setNoPersonal(String noPersonal) {
    this.noPersonal = noPersonal;
    this.outNombre.setValue(this.noPersonal);
    this.outNombre.setRendered(true); 
    this.outRfc.setStyle("text-align:left;color:red;margin-top:2px"); 
    //component.getAttributes().put("style", "color:red");
    this.outRfc.setRendered(true);        
}
  • 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-26T03:02:39+00:00Added an answer on May 26, 2026 at 3:02 am

    You can just use EL expressions in the style and styleClass attributes. You can use the conditional operator ?: in EL to print different strings based on a boolean condition.

    E.g.

    <h:someComponent styleClass="#{bean.show ? 'show' : 'hide'}" />
    

    with this getter

    public boolean isShow() {
        return show;
    }
    

    and this CSS

    .show {
        display: block;
    }
    
    .hide {
        display: none;
    }
    

    Note that the above still renders the component to the client side, so you would be able to toggle the visibility using plain JavaScript.

    Or, if you actually want to show/hide it entirely server side, then you could use the rendered attribute for this instead. It also just accepts EL expressions:

    <h:someComponent rendered="#{bean.show}" />
    

    You only need to keep in mind that when this evaluates false, then this component is not present in the client side at all, so you won’t be able to show it again using plain JavaScript or Ajax. When showing it using Ajax, you need to re-render its parent component instead.


    Update based on your new code snippet, this is not the right way. You should not bind the component to the bean for this. You should also define CSS styles in its own .css file which is much easier to maintain and keeps your bean and view from specific CSS clutter.

    E.g. (I randomly guess that the styles are dependent on some kind of error/success state)

    <h:outputText id="display_rfc" value="#{IDWizard.rfc}" rendered="#{IDWizard.show}"
        styleClass="#{IDWizard.success ? 'success' : 'error'}" />
    

    with those getters

    public boolean isShow() {
        return show;
    }
    
    public boolean isSuccess() {
        return success;
    }
    

    and this CSS

    .success {
        text-align: center;
        color: #333333;
        margin-top: 30px;
    }
    
    .error {
        text-align: left;
        color: red;
        margin-top: 2px;
    }
    

    You just have to set those booleans accordingly in bean’s (post)constructor or action(listener) method.

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

Sidebar

Related Questions

I have a style template (below) that does not update some my custom control
I'm using GNAT Programming Studio to update some ada files. I have a style
Richfaces 3.3.3, Jsf 1.2: I have a a4j:form that uses some simple validation, mainly
I have a style template (below) that does not update when my Tag binding
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
Does anyone know how I can update the style attribute of a division using
I'm wondering if it's possible to update another objects style from a stylesheet, like
Is it possible to conditionally update JSF components only when validation succeeds? I would
I have this form which can insert/update values into database table. <div id=settingsdiv style=width:350px;
I have a JSF application that is updating sections of itself dynamically via AJAX.

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.