[opencms-dev] Multiple values to a single Property?

Jonathan Woods jonathan.woods at scintillance.com
Tue Oct 10 20:29:08 CEST 2006


Thanks for the code.  Eek!  The sooner OpenCms gets itself an integrated
AJAX-like framework for editing XML content the better.
 
Here's my schema which allows me to use a multiple-select control.  I don't
currently use property mapping, so that isn't shown in this schema - but as
far as I recall it worked OK.  Ignore stuff between {{ and }}, and pretend
it's replaced with a string of your choice (I do that with Ant during build
time).
 
Jon
======
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
 
 <xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>
  
 <xsd:element name="OrganisationalUnitSets"
type="OpenCmsOrganisationalUnitSets"/>
 
 <xsd:complexType name="OpenCmsOrganisationalUnitSets">
  <xsd:sequence>
   <xsd:element name="OrganisationalUnitSet"
type="OpenCmsOrganisationalUnitSet" minOccurs="0" maxOccurs="unbounded"/>
  </xsd:sequence>
 </xsd:complexType>
 
 <xsd:complexType name="OpenCmsOrganisationalUnitSet">
  <xsd:sequence>
   <xsd:element name="OrganisationalUnitShortNames" type="OpenCmsString" />
  </xsd:sequence>
  <xsd:attribute name="language" type="OpenCmsLocale" use="optional"/>
 </xsd:complexType>
 
 <xsd:annotation>
  <xsd:appinfo>
   <resourcebundle name="{{runtime.opencms.module.name}}.workplace"/>
   <layouts>
    <layout element="OrganisationalUnitShortNames"
widget="MultiSelectWidget"
configuration="${key.standingdata.{{runtime.opencms.propertyprefix}}organisa
tionalunit}"/>
   </layouts>
   <validationrules/>
   <defaults>
    <default element="OrganisationalUnitShortNames"
value="${key.standingdata.{{runtime.opencms.propertyprefix}}organisationalun
it.defaultvalue}"/>
   </defaults>
  </xsd:appinfo>
 </xsd:annotation>  
</xsd:schema>

  _____  

From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of dinshaw gobhai
Sent: 10 October 2006 19:13
To: The OpenCms mailing list
Subject: Re: [opencms-dev] Multiple values to a single Property?


Hello there,
Thanks but I think you did have it right.
I am trying to set the value (add property) to the value of the multi
widget.
I do the same thing as you but it is passted below.
MY problem is that a JAVA developer here before me made this custom class
and I just changed the sql to return my categories. 
I believe that for the multi values i cannot use an 'extention' of the
SelectWidget but rather should be usiing the ComboBox as you are. But not
being a JAVA guy and not having a day or two to spend figuring it out i was
trying to get it to workwith the selectWidget. 
I changed the output to multiple="true" but that did not do the trick.

Here is what i am using: wuold you mind showing me the ComboBox code you are
using?


package com.bhvr.opencms.widgets;

import com.bhvr.db.DBUtil;

import org.opencms.file.CmsObject;
import org.opencms.widgets.A_CmsSelectWidget;
import org.opencms.widgets.CmsSelectWidget;
import org.opencms.widgets.CmsSelectWidgetOption; 
import org.opencms.widgets.I_CmsWidget;
import org.opencms.widgets.I_CmsWidgetDialog;
import org.opencms.widgets.I_CmsWidgetParameter;

import java.util.Iterator;
import java.util.List;

/**
 * Provides a widget for a standard HTML form select box.<p> 
 * 
 * Please see the documentation of <code>{@link
org.opencms.widgets.CmsSelectWidgetOption}</code> for a description 
 * about the configuration String syntax for the select options.<p>
 * 
 * The select widget does use the following select options:<ul>
 * <li><code>{@link
org.opencms.widgets.CmsSelectWidgetOption#getValue()}</code> for the
<code>value</code> of the HTML select box 
 * <li><code>{@link
org.opencms.widgets.CmsSelectWidgetOption#isDefault()}</code> for
pre-selecting a specific value 
 * <li><code>{@link org.opencms.widgets.CmsSelectWidgetOption#getOption
()}</code> for the <code>option</code> of the HTML select box
 * </ul>
 * <p>
 *
 * @author Andreas Zahner 
 * 
 * @version $Revision: 1.11 $ 
 * 
 * @since 6.0.0 
 */
public class CmsCategorySelectWidget extends A_CmsSelectWidget {

    /**
     * Creates a new select widget.<p>
     */
    public CmsCategorySelectWidget() {

        // empty constructor is required for class registration 
        super();
    }

    /**
     * Creates a select widget with the select options specified in the
given configuration List.<p>
     * 
     * The list elements must be of type <code>{@link
CmsSelectWidgetOption}</code>.<p> 
     * 
     * @param configuration the configuration (possible options) for the
select widget
     * 
     * @see CmsSelectWidgetOption
     */
    public CmsCategorySelectWidget(List configuration) {

        super(configuration);
    }

    /**
     * Creates a select widget with the specified select options.<p>
     * 
     * @param configuration the configuration (possible options) for the
select box 
     */
    public CmsCategorySelectWidget(String configuration) {

        super(configuration);
    }

    /**
     * @see
org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject ,
org.opencms.widgets.I_CmsWidgetDialog,
org.opencms.widgets.I_CmsWidgetParameter)
     */
    public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog
widgetDialog, I_CmsWidgetParameter param) {

        String id = param.getId();
        StringBuffer result = new StringBuffer(16);

        result.append("<td class=\"xmlTd\" style=\"height: 25px;\"><select
multiple=\"true\" class=\"xmlInput"); 
        if (param.hasError()) {
            result.append(" xmlInputError");
        }
        result.append("\" name=\"");
        result.append(id);
        result.append ("\" id=\"");
        result.append(id);
        result.append("\">");

        // get select box options from default value String
//        List options = parseSelectOptions(cms, widgetDialog, param); 

        DBUtil dbUtil = new DBUtil();
        
        javax.sql.rowset.CachedRowSet rs =
dbUtil.getCachedData("java:/comp/env/jdbc/lt", "SELECT CONCAT( REPEAT('-',
COUNT( parent.name <http://parent.name> ) - 1), node.name) AS name,"
        +" node.cat_id AS cat_id"
        +" FROM categories AS node,"
        +" categories AS parent" 
        +" WHERE node.lft BETWEEN parent.lft AND parent.rgt"
        +" GROUP BY node.cat_id"
        +" ORDER BY node.lft");
        
        List<CmsSelectWidgetOption> options = new
java.util.ArrayList<CmsSelectWidgetOption>();
 
        try {
            while (rs.next()) {
                options.add(new CmsSelectWidgetOption(rs.getString("name"),
false, rs.getString("name"))); 
            }
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
                
        
        
        String selected = getSelectedValue(cms, param);
        Iterator i = options.iterator();
        while (i.hasNext()) {
            CmsSelectWidgetOption option = (CmsSelectWidgetOption)i.next();
            // create the option
            result.append("<option value=\""); 
            result.append(option.getValue());
            result.append("\"");
            if ((selected != null) && selected.equals(option.getValue())) {
                result.append(" selected=\"selected\""); 
            }
            result.append(">");
            result.append(option.getOption());
            result.append("</option>");
        }

        result.append("</select>"); 
        result.append("</td>");

        return result.toString();
    }

    /**
     * @see org.opencms.widgets.I_CmsWidget#newInstance()
     */
    public I_CmsWidget newInstance() { 

        return new CmsCategorySelectWidget(getConfiguration());
    }
}



On 10/7/06, Jonathan Woods <  <mailto:jonathan.woods at scintillance.com>
jonathan.woods at scintillance.com> wrote: 

Dinshaw -
 
I'm sorry; I misunderstood your question, anyway.  As far I can tell, you
want the value of multiple elements to map on to a single property, whereas
in my case I was merely setting an element's 'value' (and thereby a mapped
property) using values derived from a multi-select widget.
 
Are you restricted to using a PHP application layer?  If you used Java
executing in the OpenCms context, you'd have far more flexibility - e.g.
Java could process the XML document instance whenever it wanted, maybe
setting a property to help in later querying for category-matching
resources.  I take a different approach at www.colfes.com: I index XML docs
in Lucene, and query the Lucene index at page rendering time (with some
caching) to select resources matching multiple categories.
 
By the way, is the code to your CmsCategorySelectWidget something you can
share?  I currently flatten a hierarchical value structure and represent it
in a simple SelectorWidget - ugly!
 
Jon

  _____  

From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of dinshaw gobhai
Sent: 06 October 2006 17:56
To: The OpenCms mailing list
Subject: Re: [opencms-dev] Multiple values to a single Property?



Hi Jon,
Thanks very much. I tried your sugestion and still my values are
overwritten.
My relevent schema lines are:

<xsd:element name="Category" type="OpenCmsString" />
<layout element="Category" widget="CmsCategorySelectWidget" /> 
<mapping element="Category" mapto="property:category" />

If you have a second to see if there is anything dumb in here (like I
shouldn't be using String) that would be great.
The CmsCategorySelectWidget uses a MySQL nested set modle category table to
return a tree stucture. 
Thanks again,
-Dinshaw 



On 10/6/06, Jonathan Woods <jonathan.woods at scintillance.com> wrote: 

Dinshaw -
 
I use a SelectorWidget to render a multiple-select list in a couple of my
XSDs, and I used to map the (multiple) value of this using an ordinary
<mapping> element.  OpenCms populated the property with the values selected,
separating them with a comma (or was it a semicolon? can't recall).
 
Jon

  _____  

From: opencms-dev-bounces at opencms.org [mailto:
<mailto:opencms-dev-bounces at opencms.org> opencms-dev-bounces at opencms.org] On
Behalf Of dinshaw gobhai
Sent: 05 October 2006 18:48
To: opencms-dev at opencms.org
Subject: [opencms-dev] Multiple values to a single Property?



Hi there,
I am fairly new to OpenCMS and have found references to that fact that i can
map multiple values to a single property however I can not find a guide as
to how.
If anyone could point me to a reference that would be great. 

The problem is that I  have a category select list for a content type
my_article.xsd that needs to occur multiple times so that it can appear on
different category pages simultaneously.

The catch is that the system I am working on has built a php application
layer to get and parse the OpenCMS content and they sql query needs the
property value to target the articles that should be included. 

Currently only the first instance of the Category select list is mapped to
the category property.

<mapping element="Category" mapto="property:category" />

so what i was looking for (i think) was something like 
<mapping element="Category" mapto="property:category" multiple="true" />

But i have been unable to find it.

Any help would be greatly appreciated.
Thanks,
-Dinshaw, NYC 




_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/mailman/listinfo/opencms-dev
<http://lists.opencms.org/mailman/listinfo/opencms-dev> 






_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/mailman/listinfo/opencms-dev




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20061010/0bc2da29/attachment.htm>


More information about the opencms-dev mailing list