cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonid Chumanov" <>
Subject [CForms] widget mode (readonly, output, hidden, etc.) - offer to developers
Date Thu, 02 Dec 2004 11:57:00 GMT
I know, that there are plans to make block CFORMS stable and there is a
gathering the information. I enough for a long time use this block and
me there are certain reasons which I would like to offer. Beforehand I
apologize, if I shall tell something already discussed. Earlier I did
not write and did not read this conference, I participated only in the
user conference. 
I think, it is necessary to make more flexible system of readwrite modes
in elements. In the my project I have made the following changes: 
Has entered new attribute of widget style "rwmode" (though it was
possible to use already existing type, but it is now used and as for the
task of a readwrite mode (hidden, output), and as for the type of
element (textarea, data))
Possible values of rwmode: 
invisible - the element is inaccessible and is not shown (as though it
and is not present in general) 
hidden - the element is displayed by the hidden field (same as
output - the element is displayed by the text (same as output)
output_hidden - simultaneously the element is displayed by the hidden
field and the element is displayed by the text
readonly - the element is displayed by a field of editing, but with a
grey background and attribute only reading 
readwrite (default) - a usual element of editing 
For example:
<ft:widget id="creationDate">
<fi:styling rwmode="output_hidden" format="dd/MM/yyyy"/>
Also I wanted, that it was possible to set a readwrite mode not only
from a template, but also from API. Therefore I have made the following
changes to source codes
public interface Widget {
  public static final int RWMODE_INVISIBLE = 0;
  public static final int RWMODE_HIDDEN = 1;
  public static final int RWMODE_OUTPUT = 2;
  public static final int RWMODE_OUTPUT_HIDDEN = 3;
  public static final int RWMODE_READONLY = 4;
  public static final int RWMODE_READWRITE = 5;
  public static final String RWMODE_EL = "rwmode";
  public static final String RWMODE_INVISIBLE_STR = "invisible";
  public static final String RWMODE_HIDDEN_STR = "hidden";
  public static final String RWMODE_OUTPUT_STR = "output";
  public static final String RWMODE_OUTPUT_HIDDEN_STR = "output_hidden";
  public static final String RWMODE_READONLY_STR = "readonly";
  public static final String RWMODE_READWRITE_STR = "readwrite";
  public int getRwmode();
  public void setRwmode(int rwmode);
  public int getRwmodeDefinition();
  public void setRwmodeDefinition(int rwmodeDefinition);
  public void restoreRwmodeToDefinition();
public abstract class AbstractWidget implements Widget {
    private int rwmode = RWMODE_READWRITE;
    private int rwmodeDefinition = RWMODE_READWRITE;
    public int getRwmode() {
      return rwmode;
    public void setRwmode(int rwmode) {
      this.rwmode = rwmode;
    public int getRwmodeDefinition() {
      return rwmodeDefinition;
    public void setRwmodeDefinition(int rwmodeDefinition) {
      this.rwmodeDefinition = rwmodeDefinition;
    public void restoreRwmodeToDefinition(){
      rwmode = rwmodeDefinition;
    protected void generateRWMODESaxFragment(ContentHandler
contentHandler, Locale locale) throws SAXException {
      String stringValue = "true";
      if (rwmode == RWMODE_INVISIBLE){
        stringValue = RWMODE_INVISIBLE_STR;
      else if (rwmode == RWMODE_HIDDEN){
        stringValue = RWMODE_HIDDEN_STR;
      else if (rwmode == RWMODE_OUTPUT){
        stringValue = RWMODE_OUTPUT_STR;
      else if (rwmode == RWMODE_OUTPUT_HIDDEN){
        stringValue = RWMODE_OUTPUT_HIDDEN_STR;
      else if (rwmode == RWMODE_READONLY){
        stringValue = RWMODE_READONLY_STR;
      else if (rwmode == RWMODE_READWRITE){
        stringValue = RWMODE_READWRITE_STR;
      if (rwmode != RWMODE_READWRITE){
        contentHandler.startElement(Constants.INSTANCE_NS, RWMODE_EL,
                                    Constants.INSTANCE_PREFIX_COLON +
        contentHandler.characters(stringValue.toCharArray(), 0,
        contentHandler.endElement(Constants.INSTANCE_NS, RWMODE_EL,
                                  Constants.INSTANCE_PREFIX_COLON +
and in each child Widget element I added call of function
generateRWMODESaxFragment() to function generateItemSaxFragment 
    public void generateItemSaxFragment(ContentHandler contentHandler,
Locale locale) throws SAXException {
            //some code
        generateRWMODESaxFragment(contentHandler, locale);
public class EffectWidgetReplacingPipe extends EffectPipe {
    protected class WidgetHandler extends Handler {
        public Handler process() throws SAXException {
            switch (event) {
            case EVENT_START_ELEMENT:
                widgetId = getWidgetId(input.attrs);
                widget = getWidget(widgetId);
                gotStylingElement = false;
                return this;
            case EVENT_ELEMENT:
                if (Constants.INSTANCE_NS.equals(input.uri) &&
STYLING_EL.equals(input.loc)) {
                    gotStylingElement = true;
                    //my added code start
                    String rwmode = null;
                    if (input.attrs != null){
                      rwmode = input.attrs.getValue(Widget.RWMODE_EL);
                    if (rwmode != null && widget != null){
                      if (Widget.RWMODE_INVISIBLE_STR.equals(rwmode)){
                      else if (Widget.RWMODE_HIDDEN_STR.equals(rwmode)){
                      else if
                      else if (Widget.RWMODE_OUTPUT_STR.equals(rwmode)){
                      else if
                      else {
                    //my added code end
                return bufferHandler;
            case EVENT_END_ELEMENT:
                widget = null;
                return this;
                return this;
Unfortunately it was necessary to bring in the greatest changes in xsl.
It is necessary to add checks for each element. For example: 
            <xsl:template match="fi:field">
                        <input name="{@id}" id="{@id}"
value="{fi:value}" title="{fi:hint}">
                                   <xsl:if test="fi:styling">
select="fi:styling/@*[not(name() = 'rwmode' or name() =
                                               <xsl:when test="fi:rwmode
= 'readonly'">
<xsl:attribute name="class">rdtext</xsl:attribute>
<xsl:attribute name="readonly">1</xsl:attribute>
<xsl:attribute name="class">text</xsl:attribute>
                        <xsl:apply-templates select="." mode="common"/>
            <xsl:template match="fi:field[fi:rwmode = 'invisible']"
            <xsl:template match="fi:field[fi:styling/@type='output' or
fi:rwmode = 'output']" priority="2">
                                   <xsl:when test="fi:selection-list">
name="value" select="fi:value"/>
name="selected" select="fi:selection-list/fi:item[@value = $value]"/>
<xsl:apply-templates select="$selected/fi:label"/>
<xsl:value-of select="$value"/>

View raw message