cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Johnston <coc...@lojjic.net>
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 
> http://mail-archives.apache.org/mod_mbox/cocoon-users/200507.mbox/%3cda41l4$nlj$1@sea.gmane.org%3e

> 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) {
    form.lookupWidget("my-widget").setState(
       Packages.org.apache.cocoon.forms.formmodel.WidgetState.OUTPUT
    );
}

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 
ignored.





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message