You need to sign in to do that
Don't have an account?

inputText not binding to my wrapper class
I have a VF page with Controller Extension that very much resembles the example at http://wiki.apexdevnet.com/index.php/Wrapper_Class. I had it all working great as it resembles that class.
I received a new requirement to add a String field into the wrapper and to add an inputText field onto the VF page. So I added a new "public String problemDescription {get; set;}" property into the wrapper class. I then added an inputText field with a value attribute of that field, allowing the user to enter a value, process the records and use that input value in the Apex method.
For some reason, that field in the wrapper class is not picking up the value entered into the VF page. If I hardcode a value as a default in the wrapper class constructor, that value will appear in my VF page. However, if I overwrite that value in the page, the controller will not pick up on the new value. It only uses the initial value.
The strange thing is that I have an inputCheckbox on my page bound to the selected property of the wrapper class and the controller picks up the value set on the page. For some reason, it won't pickup my new value. Ideas?
I can post the code if my explanation doesn't make sense, but I thought I'd keep it as simple as possible and ask people to start with that example on the wiki and try to add a String to the wrapper class and get the controller to read the values submitted from the page.
I received a new requirement to add a String field into the wrapper and to add an inputText field onto the VF page. So I added a new "public String problemDescription {get; set;}" property into the wrapper class. I then added an inputText field with a value attribute of that field, allowing the user to enter a value, process the records and use that input value in the Apex method.
For some reason, that field in the wrapper class is not picking up the value entered into the VF page. If I hardcode a value as a default in the wrapper class constructor, that value will appear in my VF page. However, if I overwrite that value in the page, the controller will not pick up on the new value. It only uses the initial value.
The strange thing is that I have an inputCheckbox on my page bound to the selected property of the wrapper class and the controller picks up the value set on the page. For some reason, it won't pickup my new value. Ideas?
I can post the code if my explanation doesn't make sense, but I thought I'd keep it as simple as possible and ask people to start with that example on the wiki and try to add a String to the wrapper class and get the controller to read the values submitted from the page.
If you look at the debug log when you execute the process selected, you can see any data you put in the contactList wrapper item.
Here is my version of the sample:
Page:
public void setx(String val)
{
this.x = val;
}
public String getx()
{
return x;
}
My real use case is that my client uses a Hardware__c object linked to Contracts. Cases can be associated to Contracts. There is a Service_Request_Hardware__c object that will hold the Hardware__c items being supported on a specific Case. My VF page is intended to make it easy for people to choose the Hardware__c records from the associated Contract and automatically create Service_Request_Hardware__c records when clicking Save. It's been working up until my latest requirement.
For my latest requirement, I was asked to add a problem_description__c field onto the Service_Request_Hardware__c custom object that should be populated from the page. I am unable to get the problem description field populated in the wrapper object. The selected property gets populated without issue. It just refuses to take the value in the page for the problemdescription field.
Below is my code.
FYI - that sample wrapper works just fine in my org.
Apex
VF
I'm not positive these will work but give it a try.
-Jason
Message Edited by TehNrd on 12-22-2008 11:56 AM
and the VF page to
This has to be a bug in VisualForce.
The workaround to put the column before the checkbox makes the page look really bad. It technically works, but it's kind of embarassing to tell my client that it's the only way I can get it to work.
Salesforce, what say you?
The following code works perfectly if I remove the apex:SelectList from the form altogether. However adding the selectList either before or after the <apex:inputText> fields does not allow for the form to be saved. In fact, when the SelectList is present, neither of the commandButtons function.
The following is the VF code in question:
Apex class:
Message Edited by dchasman on 12-29-2008 09:34 AM
Message Edited by TehNrd on 12-29-2008 08:46 AM
hemm wrote:
In my code, I've had an tag in there the whole time. No error is returned.
I think Doug was suggesting the pagemessages tag.
The pagemessages message take will show any messages returned by the page, whereas the messages tag will only show for the selected component.
JimRae wrote:
hemm wrote:
In my code, I've had an tag in there the whole time. No error is returned.
I think Doug was suggesting the pagemessages tag.
The pagemessages message take will show any messages returned by the page, whereas the messages tag will only show for the selected component.
Thanks for clarifying. I didn't catch that. I added the <apex:pagemessages/> tag with the same result. No messages. The record is selected and saves just fine. However, the inputText value is not captured. The inputText IS captured, however, if I make it the first column in the table.
I solved my issue. apex:messages did return an error regarding the SelectList.
The selectList was of not a multi-select list and the variable I was trying to store the selected value in was an array instead of a simple string. Once I changed that in the getter/setter methods, everything seems to be working now.
Thanks for pointing me in the right direction.
Message Edited by Colin Loretz on 12-29-2008 12:47 PM
Now that I fixed it, I see what was happening, but it was really hard to track down. The important parts of the page are:
To fix it, I render the Problem Description using the "exists" attribute instead. This attribute is set to true upon page load for existing records and is not affected by anything happening in the page.
So it's NOT a Visualforce bug. It was a change in properties that was occurring in memory, but not visually.
The lesson learned is to use fields that are un-changable in the page for the rendered attribute. If you do need to use a value that's changable in the rendered attribute, then you should re-render the dependent components upon changing that value.
Message Edited by hemm on 12-29-2008 02:03 PM
Thanks for your solution. Its saved me. :)
Thanks