Friday, 15 April 2011

jsf - Changing dynamically background color of commandbutton -


I want to change dynamically the color of commandbutton in the primaryface.

Here is the code excerpt of code:

   

Button style is the area of ​​ kkcIncomingErrorBean category:

  personal string button style = "background -color: red "; ... public string getButtonStyle () {return button style; } Public Zero Set Button Style (String Button Style) {this.buttonStyle = buttonStyle; }  

Updating the counter variable is updated but the button style is not updated.

You are confusing style With styleClass .

The style attribute should be used to declare individual code properties such that you are currently tight-coupled in your model

Styleclass attribute can be used to declare names of CSS class only, which have been declared in the normal CSS file with properties, it is finally an HTML class attribute Presents you, JSF-generated to you Attention should be given when viewed in nearby HTML output.

So you have 2 options:

  1. Use

    style attribute.

      & lt; P: command button ... style = "# {kkcIncomingErrorBean.buttonStyle}" />  
  2. Instead use a CSS class name.

      personal string button style = "error";  

    with a category declaration below in a normal CSS file.

      .error {background: red; }  

    By the way, that setter is unnecessary.

Of course, the name of a normal CSS class as shown in Option 2 is Favorites. CSS properties are not in the Java file, but in a css file.


No comments:

Post a Comment