aspose file tools*
The moose likes JSF and the fly likes Change InputText Background color after Action Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Change InputText Background color after Action Method" Watch "Change InputText Background color after Action Method" New topic
Author

Change InputText Background color after Action Method

Red Trebor
Greenhorn

Joined: Feb 25, 2013
Posts: 5
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

Joined: Feb 25, 2013
Posts: 5
I Think that it's not possible right? Maybe because the view it's already created (Restore View phase)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16061
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Red Trebor
Greenhorn

Joined: Feb 25, 2013
Posts: 5
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

Joined: Jun 25, 2001
Posts: 16061
    
  21

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

Joined: Feb 25, 2013
Posts: 5
I am using jsf 1.1 and tomahawk-1.1.9.jar
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16061
    
  21

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

Joined: Feb 25, 2013
Posts: 5
Thanks a lot, you have been really helpful!
Melvin Jose
Greenhorn

Joined: Dec 14, 2012
Posts: 2
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Change InputText Background color after Action Method