cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Johnston <>
Subject Re: Field that is either required or output
Date Sat, 28 Oct 2006 01:37:34 GMT
Bruce Atherton wrote:
> I have a problem with form fields that are editable for some people and 
> just displayed to others. When they are editable, they are required. 
> When they are not editable, they have data already and just need to be 
> displayed (and must not be required since no data will be submitted for 
> them). These requirements are dealt with in the form definition file 
> with the 'required="true"' and the 'state="output"' attributes of the 
> fd:field tag. The trouble is that I only want one or the other, and the 
> one I want needs to be determined programmatically based on who is 
> logged in.
> One solution is to duplicate the definition file and determine which one 
> to use from within the flow, but that strikes me as having a 
> copy-and-paste code smell. Another solution, which is described in this 
> email 

> suggests using jx inside your definition file and getting the definition 
> file with a cocoon: resource that goes through an internal pipeline. The 
> same email, though, warns against this approach as it cannot be cached 
> and so is very inefficient.
> Is there another preferred solution? Perhaps modifying the form model 
> from somewhere in the pipeline or flowscript to switch the state and 
> "required" validation on and off in the form model? Or adding an HTML 
> hidden field that could submit the data even if the state is output? Or 
> something else I haven't thought of? What do other people do to handle 
> this problem which must be fairly common? Any suggestions appreciated.

I use either flowscript or a fd:on-create handler to set the state of 
the widget at the time the form is created:

if(condition) {

I think this is sufficient and you don't have to switch off 
requiredness; since widgets in OUTPUT state don't read values from the 
request they are not validated anyway so the required property will be 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message