aspose file tools*
The moose likes JSF and the fly likes h:inputText readonly= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "h:inputText readonly="true" not updating managed bean values" Watch "h:inputText readonly="true" not updating managed bean values" New topic
Author

h:inputText readonly="true" not updating managed bean values

B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82
I am trying to use readonly="true" in h:inputText, hoping that the value will ultimately reach the managed bean property it is tied to, on submitting the form. The value gets submitted as a request parameter, but doesn't reach the managed bean it is tied to. I recollect facing the same problem some time back. Any ideas why the value is not reaching the managed bean.

Here is the code.



regards,
Nirvan
Americo Pinto
Greenhorn

Joined: Oct 25, 2010
Posts: 5
Hello Nirvan

I guess you must associate the inputText with a property in the managed bean

To do this instead of h:inputText use af:inputText where af is declared as xmlns:af="http://xmlns.oracle.com/adf/faces/rich"

Declare property in the bean and associate it using the binding attribute of the input text

Try iy like this

<af:inputText value="#{stateBean.selectedState}" readonly="true" binding="#{<managedbean>.<propriedad>}">
<f:converter converterId="stateConverter"/>
</af:inputText>

hope this can help you

Hugs

Américo
B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82
I am not using oracle adf faces

regards,
Nirvan
Americo Pinto
Greenhorn

Joined: Oct 25, 2010
Posts: 5
It doesn't matter if it's Oracle or not.

The idea is always the same.

You must associate the inputText with a property in the bean

Hugs,

Américo
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
I do not understand why would you transfer to using adf in any case. I do not see how the approach suggested by Americo Pinto solves anything.

Nirvan Buddha: Why would you like to send the state through user interface anyway? Do you have a good reason for doing so? User may found a way to change the property and then you have a potential security problem there.

I do not know why the readonly would prevent you getting the property back to bean but maybe it has something to do with the fact that readonly means just that (i.e. maybe JSF tries to prevent changing the property). But that is easy to test by removing the readonly and testing the code then.

If you absolutely must iterate the property through UI then then how about something like thisI did not test this.

EDIT: Maybe Americo Pinto wanted to use the value attribute of the binded component but he does not say so. And yes, that is one way of doing it if the value does indeed go to the binded component but does not populate to the value.
B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82
Americo Pinto wrote:It doesn't matter if it's Oracle or not.

The idea is always the same.

You must associate the inputText with a property in the bean
Américo


Are you talking about value binding or component binding. I have already value-bound the h:inputText using
value="#{stateBean.selectedState}". If I remove readonly="true" the value very swiftly gets passed to the managed bean. My understanding of readonly is that it just disallows the user to edit the inputText. Other things function the same.
If you are talking about component binding, maybe it will work, but that doesn't answer the question why readonly should prevent updation of value-bound property in managed bean.

regards,
Nirvan.
Americo Pinto
Greenhorn

Joined: Oct 25, 2010
Posts: 5
Everything you said is correct.

The attribute "value" works perfectly.

I don't know for what purpuse you have this inputText

If it's to be read only I don't know if it must be seen by the user or not.

If not you can use inputHidden instead

If yes try to use disabled instead of readonly

regards,

Américo
B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82
Americo Pinto wrote:Everything you said is correct.

I don't know for what purpuse you have this inputText

If it's to be read only I don't know if it must be seen by the user or not.

If not you can use inputHidden instead

If yes try to use disabled instead of readonly

regards,
Américo


My managedBean is requestscoped so I am using the readonly inputText to get the value back next time when the bean is instantiated after form submit.

User needs to see it.

I can use inputHidden, or may be store the state attribute in session scope, or perhaps make the managed bean session scoped. But there will be other screens that will need this behaviour. So I am making sure the best approach is used.

disabled does not work.

regards,
Nirvan.

Americo Pinto
Greenhorn

Joined: Oct 25, 2010
Posts: 5
If the user needs to see it then put it readonly and copy the value into an inputHidden.

You can request for the value of the inputhidden field

Or put the value in the Session and request it as well on the bean

regards,

Américo
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: h:inputText readonly="true" not updating managed bean values