How do I get the value of a UIComponent in Java?

I have a method in mine JSF

controller

that is called by a tag ajax

nested inside a visual component (not really relevant to it). The method takes a single type argument AjaxBehaviorEvent

from which I can get the Java representation of the invoking HTML of the visual component as UIComponent

, and also downgrade it to the appropriate type (for example, h:inputText

match HtmlInputText

).

I understand that in most cases the value of an HTML visual component would be easily retrieved by referencing a controller or object [g | s] etters to which form fields appear in the view. However, in my particular case, I would like to get the value of a visual component (in my case a form field) through its rendering of Java objects. While researching the API faces

, I found ways to read various properties of an object, such as ID or context , but not the value the component is currently holding in the view.

Can anyone please explain, am I just not finding the correct way to read it or is this so by design? If the latter, can you explain why it works this way? Disabling backdoor access to form fields and not view views?

+3


source to share


1 answer


There are many ways to pull values ​​from a component. Goes what you already have UIInputt#getValue()

and UIInput#getSubmittedValue()

.

UIInput#getSubmittedValue()

suitable for this purpose only between phases APPLY_REQUEST_VALUES

and VALIDATE

JSF request. Use after all other phases UIInputt#getValue()

. You will use UIInput

instead the raw UIComponent

one that you pulled from the event ( UIInput

extends UIComponent

) and this is the parent class for all input components that accept user editable values). Eventually you will see:



     UIInput theInput = (UIInput)event.getSource();
     Object theValue = theInput.getValue();

      

There are other ways (not so clean) to get values ​​in the request lifecycle as well

+4


source







All Articles