8

Within my Visualforce page I'm binding to a boolean property in a controller subclass to disable a apex:inputText control.

Page Extract:

<apex:inputText id="impressions" value="{!drop.impressionsRequested}" 
    disabled="{!dropObj.impressionsDisabled}" />

Controller subclass Extract:

public with sharing class AddDropController {
    //...
    public virtual class Drop implements Comparable {
        //...

        // Should the user be able to enter impressions?
        public boolean impressionsDisabled { get; set;}

        //...
    }
    //...
}

The page seems to load fine and the text input is disabled, but when I submit back via a command button I get an error in the page Messages:

element value must resolve to a String type!

element value must resolve to a String type!

The VF_PAGE_MESSAGE appears in the log file when the sub class properties are being assigned:

VF_PAGE_MESSAGE added when setting properties

If I remove the disabled attribute binding from the Visualforce markup the error does not occur.

Is there something I'm missing about binding to the disabled attribute?

10

Can you just use outputText instead if it needs to be disabled? Not the same appearance but might work for you?

<apex:outputText id="impressions" value="{!drop.impressionsRequested}" rendered="{!dropObj.impressionsDisabled}"/>

<apex:inputText id="impressions" value="{!drop.impressionsRequested}" rendered="{!NOT(dropObj.impressionsDisabled)}"/>

Or instead out output text you could just use a disabled HTML input element so it would maintain the same look:

<apex:outputPanel layout="none" rendered="{!dropObj.impressionsDisabled}">
    <input type="text" value="{!drop.impressionsRequested}"/>
</apex:outputPanel>
  • Is it possible to bind the values in the html <input> text? I tried doing that but I am unable to set the values in the getter/setter variable. – Sam Jul 11 '13 at 12:02
  • Toggling the rendering of the inputText rather than disabling it does work, so that is a viable solution. It does make me wonder why it breaks in the first place though. I suspect Salesforce is looking for the form value corresponding to the input binding, which didn't come back as the input was disabled. – Daniel Ballinger Jul 11 '13 at 23:11
  • Yeah I'm pretty sure they return null or something similar. I've had the same issue in the past and always jsut done this. – Matt Lacey Jul 12 '13 at 1:14
  • @sameermiraj As far as I'm aware there's no way to do that. You can use javascript events to copy the value after each key press to an <apex:inputHidden> field though. – Matt Lacey Jul 12 '13 at 1:14
1

I too, experienced this issue with inputText fields that had been updated to a disabled state via javascript. There is, however, a simpler solution in at lease some situations.

While Visualforce has issues with inputText while disabled, it handles inputFields marked as "readOnly" just fine.

ie:

j$('#id_here').attr('readOnly', true); 
1

I could not add comment to Kevin's post. "readOnly" attr works fine. Here is the code

       //Make fields read only based on profile
        $('.readOnly').each(function(i){               
            element = $(document.getElementById(this.id)); 
            element.attr('readOnly', true); 
            element.css({'background-color' : '#DFD8D1'});
            element.attr('title','Insufficient Privileges');
        });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.