function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MukulMukul 

Validation Error: Value is not valid on clicking a commandButton

Hi all,

 

I have a selectList and I am populating the values of the pick list by doing an AJAX call to a function in the controller. It all works fine but when i try to edit the values on the form and click on the submit button, it gives me an error "Value is not valid.". It forgets what the picklist values are when i click the submit button.

 

Any help is appreciated!!

 

Regards

Mukul

jwetzlerjwetzler

To give you a hint of where to start, when you do a postback the getter for your selectOptions is called again, and then iterated over to verify that the value you've selected exists in the list.

 

When other developers have run into this their getter is wiping out (or giving an inconsistent list of) values.

MukulMukul

Hi Jill,

 

 Thanks tonnes for the prompt reply!

 

My set function is not getting called second time. It gets called on "onchange" event and i see the correct values in the log.

 

But when i click the command button, at that time, the set function is not getting called. Since i am in "Edit" feature, it thinks the values of the picklist are the same.

 

Do you know why the setter is not getting called?

 

Regards

Mukul

MukulMukul

Hi Jill,

 

I see what you are saying. The get method wipes off the value and gives it what is stored in the database. The set function doesnt trigger in. What should i do to make sure that the set function is called and it sets the new value?

 

Please help! Its very urgent!!!!

 

Regards

Mukul

MukulMukul

Hi Jill,

 

How do i make sure that the selectOptions function is not called again? Is it in my control?

 

Regards

Mukul

aamDevaamDev

Hi Mukul,

 

Did you ever find a solution to this issue? I'm running across the same issue. I saw another post you particpated in where someone came up with a javascript solution. Did this work for you or did you find another solution? Any help would be greatly appreciated, I am seriously frustrated. Thanks in advance.

 

Adriel

Karimov CeyhunKarimov Ceyhun

Hi,

 

I have experienced the same problem. I think there is a little bug . The problem arrises when we try to write the list of selectoption to the variable in controller.   The point is that, when we select mutiselect=true, we must read values from variable of type list<selectoption>  and write values to variable of type list<string>.

 

for example.

 

apex:selectList id="selectedSelectList"  value="{!selectedSelectList}" multiselect="true" style="width:180px" size="10">
                        <apex:selectOptions value="{!availableSelectList}"/>
                    </apex:selectList>

here availablelist is of type list<selectoption> and selectedselectlist is of type list<string>.

 

 

Thanks.

 

Ceyhun Karimov

jwetzlerjwetzler

You should not need javascript. Your available values come from a List<SelectOption> but when your form is posted, the string that's in the "value" field of your SelectOption object is what gets added to your List<String>.

 

It will work just fine as long as your {!availableSelectList} is idempotent.

Karimov CeyhunKarimov Ceyhun

Hi,

 

Yes you are rigth. But in my case, i change the picklists. That is, i have several picklists and in order to change values between this picklists in clients side, i must use javascript. However when i do this, it gives me error again.I think than salesforce checks previous and later values in posted value, if it is modified (by javascript) it giivess error: "invalid value....". Isn't it weird that we are not allowed to play with values of picklist in client side?(in visual force page).

 

 

Thanks

 

Ceyhun Karimov 

jwetzlerjwetzler

Of course you are allowed to play with and change the values in your select list. However changing those values should be triggered by a specific action on your page and not in the getter for your options. It's not weird at all to request that your getters be idempotent -- I believe most other MVC models work the same way. You should always assume that your getters can be called any number of times during your page's lifecycle. If you want to change the values that those getters return at any point, that change should happen as a result of some type of action on your page.

Chris Wolf.ax888Chris Wolf.ax888

Jill,

 

I'm not sure about your insistence that the controller getter for SelectOption list value be idempotent. 

 

Let's take a very common scenario of three picklists representing a hierachy of geographical regions - US State, County, City; these three have onchange actions in the controller that cause cascading re-population of the backing list of SelectOption for the down-hierchy select lists. 

 

When the page is first loaded the "state" drop-down will be populated with fifty US States. Depending on the selection of the first drop-down, US State, the second drop-down will be dynamically populated with the Counties (or for LA, Parishes) for the selected value in the first drop-down (States).   By the same logic, the Counties drop-down will dynamically populate the Cities drop-down with a list of major cities in the selected Counties drop-down.

 

When the page is first loaded, the selected State will default to the first in the list, say Alaska (AL), the controller uses this value (AL) to set the default list of Counties in the second drop-down, and similarly, the default selection will be the first County in that list - finally the Cities drop-down defaults to the cities in the first county in the counties list.

 

This works upon page load.  Now if we select a different US State, the previous list of counties is overwritten by a new list of counties for the newly selected State, now the second drop-down (counties list) also has an onchange action to re-populate the list of cities drop-down.   In my case the cascading change from State => County works, but then when the change to County cascades, in the controller, to re-populate the list of Cities, then I get "Validation Error: Value is not valid",  after the initial partia page refresh of the effected drop-downs, upon submitting the form with these values.

 

If what you're saying is true, then I would expect to see this error even at the first cascading change from State to County (county list updated when State onchange action occurs) - but I don't see it happen in this cascading change.   If I use a tool to view the result of the partial-page refresh of the cities select list (the tool allows view-source of DHTML generated HTML, i.e. document.write) - I see that it never updated with the new values in the controller, so now that list dosn't match, which explains the error.   But why didn't it update if the apex:actionSupport rerender attribute for the Counties drop-down specifies that the Cities drop-down should re-render?

 

If I manually select a different County after a partial-page resfresh resulting from changing the State, then the Cities drop-down *does* get re-rendered with the updated list of cities and it works. 

 

This seem like a proplem of cascading partial-page refresh, rather then the SelectOption list not being idempotent.

jwetzlerjwetzler

Then I think you may want to surround your selectLists with an actionRegion component so that when your AJAX request is made the only portion of the form that is submitted is the changing selectList.

 

Edit: To clarify, try putting each selectList with an onchange action in its own actionRegion.

<apex:actionRegion>
<apex:selectList value="{!state}"/>
</apex:actionRegion>

<apex:actionRegion>
<apex:selectList value="{!county}"/>
</apex:actionRegion>

<apex:selectList value="{!city}"/>

 

Chris Wolf.ax888Chris Wolf.ax888

Jill,

 

Thanks for the suggestion - I'll keep that in mind.  Actually, I have to admit that the State=>County=>City scenario was contrived because I didn't want to use my actual business case on these boards.  In my actual business case, the cascading, hierarchically dependent drop-downs has the third drop-down populated from a field of type picklist/multi-select and this is where my error was really coming from.  

 

With my meager sample data in the sandbox, there was only one of the picklist items selected, so it accidentally rendered correctly with apex:selectList.  As soon as I selected more then one item, I noticed that the drop-down was rendered, still with only one item, but the label was a semi-colon delimited list of the multiply selected items.   The reason I was not using apex:inputField to allow this to properly render the multi-select picklist, is because I have to use a wrapper object  type to feed my pageBlockTable, and like the SFDC datepicker, the multi-select field must be a an actual sObject field - it can't be an arbitrary object property.

 

I assume I would have to create a custom component to render the multi-select value; when rendering, splitting by semi-colon - and when posting back,  reassembling the string array into a single semi-colon delimited list - correct?

 

Until I solve how to render a multi-select picklist from an arbitrary object property (wrapper object), I made the picklist non-multiselect and the three cascading drop-downs work as expected and described in my contrived State=>County=>City scenario.

 

Thanks,

 

Chris