cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonid Chumanov" <lchuma...@framedoc.ru>
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
type=hidden)
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"/>
</ft:widget>
 
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 +
RWMODE_EL,
                                    XMLUtils.EMPTY_ATTRIBUTES);
        contentHandler.characters(stringValue.toCharArray(), 0,
                                  stringValue.length());
        contentHandler.endElement(Constants.INSTANCE_NS, RWMODE_EL,
                                  Constants.INSTANCE_PREFIX_COLON +
RWMODE_EL);
      }
    }
//:
}
 
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;
                out.bufferInit();
                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)){
 
widget.setRwmodeDefinition(Widget.RWMODE_INVISIBLE);
                      }
                      else if (Widget.RWMODE_HIDDEN_STR.equals(rwmode)){
 
widget.setRwmodeDefinition(Widget.RWMODE_HIDDEN);
                      }
                      else if
(Widget.RWMODE_OUTPUT_HIDDEN_STR.equals(rwmode)){
 
widget.setRwmodeDefinition(Widget.RWMODE_OUTPUT_HIDDEN);
                      }
                      else if (Widget.RWMODE_OUTPUT_STR.equals(rwmode)){
 
widget.setRwmodeDefinition(Widget.RWMODE_OUTPUT);
                      }
                      else if
(Widget.RWMODE_READONLY_STR.equals(rwmode)){
 
widget.setRwmodeDefinition(Widget.RWMODE_READONLY);
                      }
                      else {
 
widget.setRwmodeDefinition(Widget.RWMODE_READWRITE);
                      }
                      widget.restoreRwmodeToDefinition();
                    }
 
                    //my added code end
 
                }
                return bufferHandler;
 
            case EVENT_END_ELEMENT:
                stylingHandler.recycle();
                stylingHandler.setSaxFragment(out.getBuffer());
                stylingHandler.setContentHandler(getContentHandler());
                stylingHandler.setLexicalHandler(getLexicalHandler());
                widget.generateSaxFragment(stylingHandler,
pipeContext.getLocale());
                widget = null;
                out.bufferFini();
                return this;
 
            default:
                out.copy();
                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">
                                               <xsl:copy-of
select="fi:styling/@*[not(name() = 'rwmode' or name() =
'submit-on-change')]"/>
                                   </xsl:if>
                                   <xsl:if
test="fi:styling/@submit-on-change='true'">
                                               <xsl:attribute
name="onchange">forms_submitForm(this)</xsl:attribute>
                                   </xsl:if>
                                   <xsl:choose>
                                               <xsl:when test="fi:rwmode
= 'readonly'">
 
<xsl:attribute name="class">rdtext</xsl:attribute>
 
<xsl:attribute name="readonly">1</xsl:attribute>
                                               </xsl:when>
                                               <xsl:otherwise>
 
<xsl:attribute name="class">text</xsl:attribute>
                                               </xsl:otherwise>
                                   </xsl:choose>
                        </input>
                        <xsl:apply-templates select="." mode="common"/>
            </xsl:template>
 
 
            <xsl:template match="fi:field[fi:rwmode = 'invisible']"
priority="2"/>
 
            <xsl:template match="fi:field[fi:styling/@type='output' or
fi:rwmode = 'output']" priority="2">
                        <xsl:choose>
                                   <xsl:when test="fi:selection-list">
                                               <xsl:variable
name="value" select="fi:value"/>
                                               <xsl:variable
name="selected" select="fi:selection-list/fi:item[@value = $value]"/>
                                               <xsl:choose>
                                                           <xsl:when
test="$selected/fi:label">
 
<xsl:apply-templates select="$selected/fi:label"/>
                                                           </xsl:when>
 
<xsl:otherwise>
 
<xsl:value-of select="$value"/>
 
</xsl:otherwise>
                                               </xsl:choose>
                                   </xsl:when>
                                   <xsl:otherwise>
                                               <xsl:copy-of
select="fi:value/node()"/>
                                   </xsl:otherwise>
                        </xsl:choose>
            </xsl:template>
 
 
 

Mime
View raw message