• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Change InputText Background color after Action Method

 
Red Trebor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,
I would like to change the background color after the execution of the action method. I am using jsf 1.1. Here's the code, I hope somebody can help me:

UIViewRoot root = FacesContext.getCurrentInstance().getViewRoot();
HtmlInputText in= (HtmlInputText)root.findComponent("formName:panelA:tabPerson:surname");
in.setValue("100");
in.setStyle("background-color: red;");
in.getAttributes().put("style","background-color:red;");
in.updateModel(FacesContext.getCurrentInstance());
FacesContext.getCurrentInstance().setViewRoot(root);
return "action_url";

The value is setted to 100, but the background color doesn't change...any ideas?
 
Red Trebor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Think that it's not possible right? Maybe because the view it's already created (Restore View phase)
 
Tim Holloway
Saloon Keeper
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is is necessary to write complex platform-specific code to do that?


A simple AJAX render of this control after changing the surnameStyle property suffices.

Also, your setValue isn't going to work. A) This is an INPUT control, and you haven't defined a place where the input value will be stored. B) setValue wants an evaluated EL expression, NOT a simple value.
 
Red Trebor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean Ajax4JSF? I have a <h:commandLink> and I would like to execute a Javascript function after the action method, to change the backgroundcolor of inputtext element/s if necessary.
 
Tim Holloway
Saloon Keeper
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several different ways to code AJAX, depending on what version of JSF you are using and whether or not you are using a third-party extension tag library. In JSF2, the core tagset provides an AJAX tag. In RichFaces 3, there's an "a4j:support" tag. Other extensions have their own variants.

You don't need to use any JavaScript to change the color if the AJAX function sets it in the backing bean and the ajax tag directs the input control to be re-rendered.
 
Red Trebor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using jsf 1.1 and tomahawk-1.1.9.jar
 
Tim Holloway
Saloon Keeper
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recommend upgrading the JSF version. You'd need to add in some other extension tagset to be able to do general AJAX on JSF 1 without brute-force coding, though. That version of Tomahawk doesn't have anything nor does core JSF 1.x.
 
Red Trebor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, you have been really helpful!
 
Melvin Jose
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Red Trebor wrote:You mean Ajax4JSF? I have a <h:commandLink> and I would like to execute a Javascript function after the action method, to change the backgroundcolor of inputtext element/s if necessary.


i just tried part of your code on JSF 2.0 and it seems to work. i created a backing bean and named it 'hello_backing', declared an HtmlInputText inputText and wrote a method called 'submitAction' with code 'inputText.setStyle("background-color: brown;");' and obviously used the component binding feature on the inputText tag using EL-'binding="#{hello_backing.inputText}, finally 'action="#{hello_backing.submitAction}' for the command button.
seems to work fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic