Readonly and form submission
Hi,
I have a real problem with form submissions and readonly text fields. The problem occurs when I have a readonly text field and a field which is requirted to have a value. An example:
<f:view>
<h:form>
<h:inputText
id="test"
value="#{Test.param1}"
readonly="true"/>
<h:inputText
id="test2"
value="#{Test.param2}"
required="true"/>
<h:inputText
id="test3"
value="#{Test.param3}"/>
<h:commandButton
action="#{Test.doTest}"
value="Ok"/>
</h:form>
</f:view>
When showing this form the first time there will be a value in the text field with id test. When submitting this form and the form isn't correctly validated the user will be returned to the same page BUT there will be no value in the text field with id test but all other values, that were filled in, will be displayed. Is there a way around this so a value in the read only can be redisplayed even thugh the form isn't correctly validated?
Thanks in advance
Message was edited by:
klejs
[1400 byte] By [
klejsa] at [2007-11-26 15:05:28]

# 2
I guess that the getters and the setters are already set .. Otherwise he will got completely other results ;)
My guess is that it is a request-scoped bean and that the value for param1 is retrieved only once and not per view? If so, then try to add <h:inputHidden value="#{test.param1}" /> to save the param value from view to view.
But anyway please show relevant parts of the backing bean code. Where and how do you load and store param1? Can you please provide a reproduceable code snippet? This sounds to me like a bug or just an unwanted feature. Even readonly params have to be submitted with the form.
# 3
Hi,
Balus is right, they are already set and the bean is in a request scope.
The backing bean looks something like this:
public class Test {
private String param1;
private String param2;
private String param3;
public String getParam1() {
return param1;
}
public void setParam1(String param1) {
this.param1 = param1;
}
public String getParam2() {
return param2;
}
public void setParam2(String param2) {
this.param2 = param2;
}
public String getParam3() {
return param3;
}
public void setParam3(String param3) {
this.param3 = param3;
}
public String prepareUpdate() {
MyClass mc = service.getMyClass(someId);
this.param1 = mc.getParam1();
this.param2 = mc.getParam2();
this.param3 = mc.getParam3();
return "success";
}
public String doTest() {
return "success";
}
}
The prepareUpdate() method is called to initialize the backing bean and then the jsp page is shown and my problems begin.
Thanks in advance
# 4
Try if adding a h:inputHidden for param1 will solve the problem.
Edit:
I can reproduce it. Adding a h:inputHidden for param1 despitely will not solve the problem. When removing the "readonly" attribute, then it works. This just sounds like an unwanted feature of maybe a bug.
I suggest you to replace the JSF validator by validation directly in the backing bean's action method. A somewhat nasty workaround, but this approach has some pro's.
Message was edited by:
BalusC
# 5
Yeah, I tried using the inputHidden tag as well without success. Putting the validation in the action method doesn't solve the problem either. The property for the readonly field is still not sent to the backing bean and on postback the property then isn't available and the readonly field is empty.
This is really, really annoying and it should be easy to solve. I have searched the threads in this forums and have found other people with the same problem but no one have come up with any solution.
/klejs