cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Derek Hohls" <DHo...@csir.co.za>
Subject [SOLVED] Re: [CForms] How to set multivalue widget's values ?
Date Mon, 21 Jun 2004 12:51:18 GMT
Johannes

You're a star!  That's exactly what I needed to do.
You think that having used XSL for n years, I would
be used to adding a $ to the variable name... 

Derek

>>> jc.textor@gmx.de 2004/06/21 01:32:56 PM >>>
Hi Derek,

now while trying out your code I discovered something that really has
nothing
to do with CForms:

<jx:forEach var="thisTheme" items="atheme">
<li>A Selection 1: ${atheme}</li>
</jx:forEach>

the syntax is simply wrong. it should say

<jx:forEach var="thisTheme" items="${atheme}">
<li>A Selection 1: ${thisTheme}</li>
</jx:forEach>

now this should help ;)

Derek Hohls wrote:

>Johannes
>
>Still no luck - I have tried adding in some more variables
>to test; and it looks like the values are being stored in
>the array OK...
>
>    var values = Array();
>  
>    for( i = 0; i < model.theme.length ; i ++ )
>      values[i] = model.theme[i];  
>      
>    var test0 = values[0];
>    var test1 = values[1];
>
>    cocoon.sendPage("ijx-page", { "atheme":values, "theme":values,
>"test0":test0; "test1":test1 });
>
>The output for test0 or test1 matches the mulivalue widget
>selection BUT the "values" output in the JX for-each loop is 
>still the  strange references as before...
>
>What else to try ??
>Derek
>
>  
>
>>>>jc.textor@gmx.de 2004/06/21 11:49:16 AM >>>
>>>>        
>>>>
>Derek,
>
>I actually don't use the values this way, I insert them directly into

>the database
>after the form was submitted.
>Let's examine your code though, since you should be able to use the 
>values in jxt
>as well.
>
> var model = form.getModel();  
>  var atheme = model.theme; /* theme is multiselect box */
>  cocoon.sendPage("jxpage", { "atheme":atheme, "theme":model.theme
});
>
>There is something subtile here. "model.theme" is an object of type
>ScriptableWidget,
>so JXT will be confused when you pass it as a collection. (and print
>out the "value"
>org.apache.cocoon.forms.flow.javascript.ScriptableWidget@e1fb6c) 
>
>I suggest retrieving the values to a native JavaScript array and
>passing that one 
>to JXT. 
>
> var model = form.getModel();  
> var values = Array();
> for( i = 0; i < model.theme.length ; i ++ )
>	values[i] = model.theme[i];
> cocoon.sendPage("jxpage", { "atheme":values, "theme":values });
>
>Does this work? It's just the solution to my problem applied in the
>opposite direction :)
>
>HTH, Johannes
>
>Derek Hohls wrote:
>
>  
>
>>Johannes
>>
>>I have tried what you suggested - the problem
>>is displaying the results in the JXTemplate - could 
>>you please post your code snippet, as what I have 
>>tried does not work....
>>
>>ie. 
>>
>>in flowscript:
>>
>>var model = form.getModel();  
>> var atheme = model.theme; /* theme is multiselect box */
>> cocoon.sendPage("jxpage", { "atheme":atheme, "theme":model.theme 
>>});
>>
>>in jxtemplate:
>>
>> <jx:forEach var="thisTheme" items="theme">
>>   <li>Selection: ${theme}</li>
>> </jx:forEach>
>> 
>> <jx:forEach var="thisTheme" items="atheme">
>>   <li>A Selection 1: ${atheme}</li>
>> </jx:forEach>
>>   
>> <jx:forEach var="thisTheme" items="atheme">
>>   <li>A Selection 2: ${thisTheme}</li>
>> </jx:forEach>   
>>
>>in output html:
>>
>>Selection:
>>org.apache.cocoon.forms.flow.javascript.ScriptableWidget@e1fb6c 
>>A Selection 1:
>>org.apache.cocoon.forms.flow.javascript.ScriptableWidget@41825e 
>>A Selection 2:
>>org.apache.cocoon.generation.JXTemplateGenerator$Expression@d622e5 
>>
>>I am obviously missing some crucial conversion ?!
>>
>>Thanks
>>Derek
>>
>> 
>>
>>    
>>
>>>>>jc.textor@gmx.de 2004/06/21 08:35:47 AM >>>
>>>>>       
>>>>>
>>>>>          
>>>>>
>>Hi Derek + all,
>>
>>I got this solved in the meantime. Actually I had to create a
>>temporary
>>array and then set the multivalue model to this array:
>>
>>var model = form.getModel();
>>
>>var rubriken = Array();
>>
>>for( i = 0 ; i < size ; i ++ )
>>   rubriken[i] = new java.lang.Integer(val[i]);
>>
>>model.rubriken = rubriken;
>>
>>Notice the difference to the code quoted below: Modifying the model
>>directly did NOT work, as it is actually an object of type widget
and
>>    
>>
>
>  
>
>>something
>>gets messed up. This is because internally, a setter method is
called
>>when
>>assigning something to model.rubriken. Took me some hours to figure
>>this
>>out, as I'm a CForms beginner :)
>>
>>I think I will put a stripped-down version of my article management
>>    
>>
>on
>  
>
>>the
>>wiki when I'm done - it's based on CForms + Woody + Hibernate and
>>    
>>
>uses
>  
>
>>a few more widgets than the present sample.
>>
>>Derek, you can read values from the model like this:
>>
>>var model = form.getModel();
>>var vals = model.rubriken // retrieve array from multivalue widgets
>>
>>Now, vals is an array which contains all the values of the options 
>>selected by
>>the user.
>>
>>Derek Hohls wrote:
>>
>> 
>>
>>    
>>
>>>And maybe the same person knows how to
>>>*get* the values from the CForm multivalue widget
>>>and display them using a JXTemplate loop??
>>>
>>>A sample showing both of these would be *very*
>>>helpful and (IMO) needs to be  a part of the
>>>Cocoon forms samples.
>>>
>>>Thanks
>>>Derek
>>>
>>>
>>>
>>>   
>>>
>>>      
>>>
>>>>>>jc.textor@gmx.de 2004/06/20 09:25:06 PM >>>
>>>>>>      
>>>>>>
>>>>>>         
>>>>>>
>>>>>>            
>>>>>>
>>>Hi all,
>>>
>>>I'm going nuts trying to set values in a CForm multivalue widget.
>>>
>>>I obtained the Form model with:
>>>
>>>var model = form.getModel();
>>>
>>>Then I tried to set the values like this:
>>>
>>>model.rubriken = Array(size);
>>>for( i = 0 ; i < size; i++)
>>>  model.rubriken[i] = new java.lang.Integer(val[i]);
>>>
>>>When size=0, everything is fine. Otherwise, I get
>>>
>>>Cannot set value of field "rubriken" with an object of type 
>>>org.mozilla.javascript.UniqueTag
>>>
>>>When I omit the array declaration, I get null pointer exceptions.
>>>
>>>Has anybody done this and can explain me how ?
>>>
>>>TIA, Johannes
>>>      
>>>



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


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.


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


Mime
View raw message