cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Hoskens ...@schaubroeck.be>
Subject Re: [cforms] struct and class display
Date Fri, 13 Aug 2004 07:23:42 GMT
Whenever you have a union widget, you need a case widget that holds the 
id of the currently chosen unionpart (struct) in its valuefield. You 
might understand it better with a little example:

Lets say you have some heterogeneous repeater, some fields may contain 
input, other's just a value to show.
definition: (don't forget the fd:new id="myclass", I don't mention them 
here explicitly, but you do want to create an instance of course)
<fd:class id="myclass">
       <fd:widgets>
       <!-- make sure to use a field widget with a selection list for 
the 'case' widget of the following union -->
       <fd:field id="input_type">
          <fd:datatype base="string"/>
               <fd:selection-list>
                    <fd:item value="no_input">   <!-- the value is the 
id of a struct below, this will make that struct visible if chosen -->
                        <fd:label>No input</fd:label> <!-- label not 
really needed if the select-widget isn't shown to user-->
                        </fd:item>
                        <fd:item value="input">
                            <fd:label>Input</fd:label>
                        </fd:item>
                    </fd:selection-list>
                </fd:field>
                <fd:union case="input_type" default="no_input" 
id="input_union">
                    <fd:widgets>
                        <fd:struct id="no_input">   <!-- Notice the same 
id as above in the selection, this struct will simply show the field-->
                            <fd:widgets>
                               <fd:output id="some_output_field">
                                          <fd:datatype base="string"/>
                                </fd:output>
                            </fd:widgets>
                        </fd:struct>
                        <fd:struct id="input">
                            <fd:widgets>
                                <fd:field id="some_input_field"><!-- 
this will give an input field to change the value-->
                                    <fd:datatype base="string"/>
                                </fd:field>
                            </fd:widgets>
                        </fd:struct>
                    </fd:widgets>
                </fd:union>
            </fd:widgets>
        </fd:class>

your template may look like:
<ft:class id="myclass">
            <ft:widget id="input_type"><fi:styling 
type="hidden"/></ft:widget> <!-- I set the selection widget hidden, I 
want the source xml document data to make the choice-->
            <ft:union id="input_union">
                <ft:case id="no_input">
                    <ft:struct id="no_input">
                        <ft:widget id="some_output_field"/> <!-- non 
editable-->
                </ft:case>
                <ft:case id="input">
                    <ft:struct id="input">
                        <ft:widget id="some_input_id"/><!-- edit field-->
                    </ft:struct>
                </ft:case>
            </ft:union>
        </ft:class>

let the binding field take care of the selection:
<fb:class id="myclass">
        <fb:javascript id="input_type" path="." direction="load">
            <fb:load-form>
                var tmp = jxpathContext.getValue("@user_changable");
                if (tmp != null)
                {
                    var userChangable = new java.lang.String(tmp);
                    if (userChangable.equals("yes"))   
                    {
                        widget.setValue("input");
                    }    else    {
                        widget.setValue("no_input");
                    }
                }
          </fb:load-form>
        </fb:javascript>
        <fb:union id="input_union" path=".">
            <fb:case id="no_input" path=".">
                <fb:struct id="no_input" path=".">
                     <fb:value id="some_output_field"/>
                </fb:struct>
            </fb:case>
            <fb:case id="input" path=".">
                <fb:struct id="input" path=".">
                    <fb:value id="some_input_field" path="."/>
                </fb:struct>
            </fb:case>
        </fb:union>
    </fb:class>

This may bind the xml data if you create a repeater which has an 
instance of the class:

<some_list><!-- repeater parent path-->
           <item user_changable="yes">valueA</item><!-- surround (for 
this example) the fb:new with a fb:context path="item", so that the 
class works on "item, @user_changable and the containing textnode-->
            <item user_changable="no">valueB</item>
</some_list>

this will give an input field with valueA and an output field for valueB

Hope I minimized the typo's, it's a long bit of code ;-)

Kind Regards,
Jan


Stephane Delort wrote:

>Hi,
>
>
>
>well I can, now, access to the object in class, struct or union in my
>      flowscript (see previous thread).
>
>
>
>but then, the shame is that it does not display the form and I have a
>      "nullpointer exception" error instead.
>
>In my defintion file I have :
>
>******************************
>  <...>
>  <fd:widgets>
>
>    <fd:union id="start" default="" case="widget-id">
>      <fd:datatype base="string"/>
>      <fd:widgets>
>        <fd:new id="widgetClass"/>
>      </fd:widgets>
>    </fd:union>
>
>    <fd:class id="widgetClass">
>      <fd:widgets>
>        <fd:repeater id="inList" >
>          <fd:widgets>
>            <fd:union id="union" case="widget-id">
>              <fd:datatype base="string"/>
>              <fd:widgets>
>                <fd:struct id="simpleList">
>                  <fd:widgets>
>                    <fd:multivaluefield id="list">
>
><....>
>
>
>
>In fill the field thanks to the followwing flowscript :
>
>********************************************************
>.......
>    var myRepeater = form.lookupWidget("start").lookupWidget("inList");
>    var row = myRepeater.addRow();
>    var myUnion = row.lookupWidget("union");
>    var myDesiredStruct = myUnion.lookupWidget("simpleList");
>    var myList = myDesiredStruct.lookupWidget("list");
>    myList.setSelectionList( c, "listId", "label" );  //c is an ArrayList (collection).
>
>....
>
>
>
>then, finally here is the *template file  which get me into troubles *;
>
>*************************************************************************
><...>
>   <ft:union id="start">
>        <ft:case id="widgetClass">                     // if I put this block in
comments, the form is not display but I do not have any exception
>          <ft:new id="widgetClass"/>
>        </ft:case>
>   </ft:union>
>
>      <ft:class id="widgetClass">
>        <ft:repeater-widget id="inList">
>          <ft:union id="union">
>
>            <ft:case id="simpleList">
>              <ft:struct id="simpleList">
>                <ft:widget id="list">
>                  <fi:styling list-type="checkbox"/>
>                </ft:widget>
>              </ft:struct>
>
><...>
>
>
>
>Anyway, it appears that I can fill any field of any structure belonging to
>      my union id="union" thanks to the lookupwidget function. So, in this
>      case how doesthe union make the selection to know which structure is
>      to be displayed ?
>
>
>
>
>
>Thanks in advance for any help,
>
>Stephane
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>  
>


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


Mime
View raw message