cancel
Showing results for 
Search instead for 
Did you mean: 

How to add checkboxes, Radiobuttons to forms

nikhil
Champ in-the-making
Champ in-the-making
Hi,

Can anyone please run me through the procedure to add checkboxes and radiobuttons to forms?

is there any type like xs:simpletype (for drop downs) which can be configured for checkboxes and radiobuttons

Please help!

Regards,
Nikhil Sharma
11 REPLIES 11

nikhil
Champ in-the-making
Champ in-the-making
Task accomplished

thanks

gidion
Champ in-the-making
Champ in-the-making
how about making this post worthwhile and posting how you accomplished this task

nikhil
Champ in-the-making
Champ in-the-making
hi,
How about displaying a bit more courtesy while posting a query?


Anyway,

Visit w3schools online tutorials on XML schemas (XSDs)

http://java.sun.com/webservices/docs/1.5/tutorial/doc/XWS-Security-schema2.html

Also, some information on alfresco wiki

Regards,
Nikhil

kvc
Champ in-the-making
Champ in-the-making
In the web-client-config-wcm.xml, you can find the different types of select controls we provide in web forms:


           <widget xforms-type="xf:select1"
                   xml-schema-type="boolean"
                   javascript-class-name="alfresco.xforms.Checkbox"/>
           <widget xforms-type="xf:select1"
                   appearance="full"
                   javascript-class-name="alfresco.xforms.RadioSelect1"/>
           <widget xforms-type="xf:select1"
                 javascript-class-name="alfresco.xforms.ComboboxSelect1"/>
           <widget xforms-type="xf:select"
                   appearance="full"
                   javascript-class-name="alfresco.xforms.CheckboxSelect"/>
           <widget xforms-type="xf:select"
                   javascript-class-name="alfresco.xforms.ListSelect"/>


We have two XForms controls, one for getting an individual selection from a user, and a second for getting multiple selections from a user.  For the single selection, we can present as a single checkbox if it is a boolean type in your XSD (and have that either selected or not selected by default), or we can present as a combox box (the default) or set of radio buttons (if you add the optional appearance annotation "full").

For multi-item selects, this can be presented as a list or checkboxes.  By default, if you've a limited number of items (5), it will present as a checkbox, whether or not you set an explicit appearance annotation.  If more than 5 items, it will present as a list.  If you have a large number of items and want to force checkboxes (override the default behavior to economize screen real estate and move to a list), you can use the appearance 'Full' annotation in your XSD.

An example XSD that shows the varying ways of list items can be displayed with different defaut values and uses of these controls based on appearances attributes follows here:



<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:alf="http://www.alfresco.org"
      elementFormDefault="qualified">
  <xs:simpleType name="four_presidents">
    <xs:restriction base="xs:normalizedString">
      <xs:enumeration value="washington"/>
      <xs:enumeration value="jefferson"/>
      <xs:enumeration value="lincoln"/>
      <xs:enumeration value="roosevelt1">
        <xs:annotation>
          <xs:appinfo><alf:label>Teddy Roosevelt</alf:label></xs:appinfo>
        </xs:annotation>
      </xs:enumeration>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="four_presidents_list">
    <xs:list itemType="four_presidents"/>
  </xs:simpleType>
  <xs:simpleType name="thirteen_colonies">
    <xs:restriction base="xs:normalizedString">
      <xs:enumeration value="massachusetts"/>
      <xs:enumeration value="NH">
        <xs:annotation>
          <xs:appinfo><alf:label>new hampshire</alf:label></xs:appinfo>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="NY">
        <xs:annotation>
          <xs:appinfo><alf:label>new york</alf:label></xs:appinfo>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="connecticut"/>
      <xs:enumeration value="RI">
        <xs:annotation>
          <xs:appinfo><alf:label>rhode island</alf:label></xs:appinfo>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="NJ">
        <xs:annotation>
          <xs:appinfo><alf:label>new jersey</alf:label></xs:appinfo>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="delaware"/>
      <xs:enumeration value="maryland"/>
      <xs:enumeration value="pennsylvania"/>
      <xs:enumeration value="virginia"/>
      <xs:enumeration value="NC">
        <xs:annotation>
          <xs:appinfo><alf:label>north carolina</alf:label></xs:appinfo>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="SC">
        <xs:annotation>
          <xs:appinfo><alf:label>south carolina</alf:label></xs:appinfo>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="georgia"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="thirteen_colonies_list">
    <xs:list itemType="thirteen_colonies"/>
  </xs:simpleType>
  <xs:element name="list-test">
    <xs:complexType>
      <xs:sequence>
   <xs:element name="select1">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="four_items">
           <xs:complexType>
             <xs:sequence>
          <xs:element name="full"
                 type="four_presidents"
                                default="jefferson"
                 minOccurs="1"
                 maxOccurs="1">
                      <xs:annotation>
                        <xs:appinfo>
                          <alf:appearance>full</alf:appearance>
                        </xs:appinfo>
                      </xs:annotation>
                    </xs:element>
          <xs:element name="compact"
                 type="four_presidents"
                                default="roosevelt1"
                 minOccurs="1"
                 maxOccurs="1">
                      <xs:annotation>
                        <xs:appinfo>
                          <alf:appearance>compact</alf:appearance>
                        </xs:appinfo>
                      </xs:annotation>
                    </xs:element>
          <xs:element name="default"
                 type="four_presidents"
                                default="jefferson"
                 minOccurs="1"
                 maxOccurs="1"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="ten_items">
                <xs:complexType>
                  <xs:sequence>
          <xs:element name="full"
                 type="thirteen_colonies"
                 minOccurs="1"
                                default="NY"
                 maxOccurs="1">
                      <xs:annotation>
                        <xs:appinfo>
                          <alf:appearance>full</alf:appearance>
                        </xs:appinfo>
                      </xs:annotation>
                    </xs:element>
          <xs:element name="compact"
                 type="thirteen_colonies"
                                default="NJ"
                 minOccurs="1"
                 maxOccurs="1">
                      <xs:annotation>
                        <xs:appinfo>
                          <alf:appearance>compact</alf:appearance>
                        </xs:appinfo>
                      </xs:annotation>
                    </xs:element>
          <xs:element name="default"
                                type="thirteen_colonies"
                                default="NJ"
            minOccurs="1"
            maxOccurs="1"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
       </xs:sequence>
     </xs:complexType>
   </xs:element>
   <xs:element name="select">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="four_items">
           <xs:complexType>
             <xs:sequence>
          <xs:element name="full"
                 type="four_presidents_list"
                                default="jefferson"
                 minOccurs="1"
                 maxOccurs="1">
                      <xs:annotation>
                        <xs:appinfo>
                          <alf:appearance>full</alf:appearance>
                        </xs:appinfo>
                      </xs:annotation>
                    </xs:element>
          <xs:element name="compact"
                 type="four_presidents_list"
                                default="jefferson"
                 minOccurs="1"
                 maxOccurs="1">
                      <xs:annotation>
                        <xs:appinfo>
                          <alf:appearance>compact</alf:appearance>
                        </xs:appinfo>
                      </xs:annotation>
                    </xs:element>
          <xs:element name="default"
                 type="four_presidents_list"
                                default="jefferson"
                 minOccurs="1"
                 maxOccurs="1"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="ten_items">
                <xs:complexType>
                  <xs:sequence>
          <xs:element name="full"
                 type="thirteen_colonies_list"
                 minOccurs="1"
                                default="NJ"
                 maxOccurs="1">
                      <xs:annotation>
                        <xs:appinfo>
                          <alf:appearance>full</alf:appearance>
                        </xs:appinfo>
                      </xs:annotation>
                    </xs:element>
          <xs:element name="compact"
                 type="thirteen_colonies_list"
                                default="massachusetts"
                 minOccurs="1"
                 maxOccurs="1">
                      <xs:annotation>
                        <xs:appinfo>
                          <alf:appearance>compact</alf:appearance>
                        </xs:appinfo>
                      </xs:annotation>
                    </xs:element>
          <xs:element name="default"
                                type="thirteen_colonies_list"
                                default="maryland"
            minOccurs="1"
            maxOccurs="1"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
       </xs:sequence>
     </xs:complexType>
   </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

nikhil
Champ in-the-making
Champ in-the-making
thanks a ton Kevin!!!

suniil
Champ in-the-making
Champ in-the-making
Thanks kevin really useful.

I'd like to populate the list item from an XML file. can you please let me know where should i place the the XML file that need to be read by corresponding schema?

Many thanks in Advance.

S

kvc
Champ in-the-making
Champ in-the-making
To generate this list dynamically from an XML, you'll need to leverage an in-line JSP callout.  That JSP should be locating in your Web Project (in Staging) so that it can be executed via the Virt Server (i.e., you'll need to have that enabled).

That JSP will need to read from the file-system (if you've CIFS mounted) or use AVMRemote (the RMI interface to an AVM repository).  You can find examples of this in our training material, in our PR example (list of Company Footers) or by checking out from SVN and accessing our unit-tests for callouts in the web-client directory.

Kevin

PS … These lists really should be dynamically generated from an XML, so that business users can readily modify lists of selectable items.  That was the driver for in-line JSP callouts.  Remember, your JSP needs to return the simpleType to your XSD … once again, the examples should help here.

suniil
Champ in-the-making
Champ in-the-making
Back on project Smiley Happy

Thanks kevin, that worked! But if we try to load the XML as you mentioned #, the interface display the content in listbox and able to select multiple choices. But FireFox browser refuses to generate the XML & HTML and throwing an error "Please provide a vaid value for xxxxxxxx". Same works perfectly with IE browsers.

#
<xs:include schemaLocation="/views/components/channel-list.jsp"/>

Alfresco version I use: 2.1 community

Any thoughts?

sbzoom
Champ in-the-making
Champ in-the-making
Hey there.
I have 2.2.0E and I dropped that xsd in exactly as is and it didn't work.

Here is the error I got in the UI:

Step Two - Author Web Content
Enter your document content into the repository.
org.alfresco.web.forms.FormProcessor$ProcessingException: org.alfresco.web.forms.xforms.FormBuilderException: error parsing schema: at line 19 column 42: src-resolve.4.1: Error resolving component 'four_presidents'. It was detected that 'four_presidents' has no namespace, but components with no target namespace are not referenceable from schema document 'null'. If 'four_presidents' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'four_presidents' has no namespace, then an 'import' without a "namespace" attribute should be added to 'null'.

And here is what is in the log file:

18:33:36,502 ERROR [org.alfresco.web.ui.common.Utils] org.alfresco.web.forms.xforms.FormBuilderException: error parsing schema:
at line 19 column 42: src-resolve.4.1: Error resolving component 'four_presidents'. It was detected that 'four_presidents' has no namespace, but components with no target namespace are not referenceable from schema document 'null'. If 'four_presidents' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'four_presidents' has no namespace, then an 'import' without a "namespace" attribute should be added to 'null'.

org.alfresco.web.forms.FormProcessor$ProcessingException: org.alfresco.web.forms.xforms.FormBuilderException: error parsing schema:
at line 19 column 42: src-resolve.4.1: Error resolving component 'four_presidents'. It was detected that 'four_presidents' has no namespace, but components with no target namespace are not referenceable from schema document 'null'. If 'four_presidents' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'four_presidents' has no namespace, then an 'import' without a "namespace" attribute should be added to 'null'.

        at org.alfresco.web.forms.xforms.XFormsProcessor.process(XFormsProcessor.java:145)
        at org.alfresco.web.forms.xforms.XFormsProcessor.process(XFormsProcessor.java:121)
        at org.alfresco.web.ui.wcm.component.UIFormProcessor.encodeBegin(UIFormProcessor.java:123)
        at javax.faces.webapp.UIComponentTag.encodeBegin(UIComponentTag.java:467)
        at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:320)
        at org.apache.jsp.jsp.wcm.create_002dweb_002dcontent_002dwizard.create_002dxml_jsp._jspx_meth_wcm_005fformProcessor_005f0(create_002dxml_jsp.java:97)
        at org.apache.jsp.jsp.wcm.create_002dweb_002dcontent_002dwizard.create_002dxml_jsp._jspService(create_002dxml_jsp.java:70)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
        at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:965)
        at org.apache.jsp.jsp.wizard.container_jsp._jspService(container_jsp.java:524)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:399)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
        at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
        at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
        at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
        at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
        at java.lang.Thread.run(Thread.java:595)

I'm just not sure what I have to change to make it work.  Any help is much appreciated.


Charlie