1

I have created a VisualForce page that is basically a wall of inputFields. I had a requirement to make all of the inputFields into outputFields when a certain event happens (the event happens, all inputFields change into outputFields at the same time).

So far, what I have done, is that I have put inputFields in their own section (500+ lines of code), and I have also put outputFields in their own section (another 500+ lines of code).

The problem is, sometimes I get so many fields, I put the inputFields in, but then I forget to put some of the output fields in. This gets my testers complaining that I missed something.

Is there an easier or better way of doing this? Obviously I need to do better testing myself, however, it would be nice if I didn't have to basically duplicate code for every field, and potentially miss a field.

Thanks for your time.

  • 1
    You could have a piece of javascript that will disable the input fields and make them read-only. The main disadvantage to this is that you still send the fields as part of the form submission and someone might change the value. Let me know if it works for you and will probably add some sample code – Mihai Neagoe Oct 28 '15 at 20:43
2

You could use a fieldset to display the fields on the page. apex:repeat over the fieldset fields and create an inputField and an outputField for every var in the repeat.

This would reduce your code to a great extent and also remove the possibility of adding only an input but not an output or vice versa

| improve this answer | |
  • I should have put in my requirement that there are different sections as well. If I had a field set for each section, I suppose that would work! – Sean McMickle Oct 29 '15 at 14:11

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.