版權所有:(xiaodaoxiaodao)藍小刀
??
xiaodaoxiaodao@gmail.com
http://m.tkk7.com/xiaodaoxiaodao/archive/2007/11/17/161240.html
?
???
??
轉載請注明來源/作者
?
alfresco WCM
在表單中自定義下拉框
?
alfresco
中使用WCM創建content的時候,如何在表單中使用自定義下拉框。
?
假設有一個webform,名稱為news,使用news.xsd。我們知道xsd文件可以使用:
<
xs:include
schemaLocation
="
/select_list_choices.xsd
"/>
?
include
一個xsd,
select_list_choices.xsd
代碼如下
(
注意,下面的下拉框選擇項比較少時,比如5個可能不會顯示為下拉框,而是顯示為radio button):
<?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="
select_list_choices
">
??????? <xs:restriction base="xs:string">
??????????? <xs:enumeration value="channel01">
??????????????? <xs:annotation>
??????????????????? <xs:appinfo>
??????????????????????? <alf:label>
財經新聞</alf:label>
??????????????????? </xs:appinfo>
??????????????? </xs:annotation>
??????????? </xs:enumeration>
??????????? <xs:enumeration value="channel02">
??????????????? <xs:annotation>
??????????????????? <xs:appinfo>
??????????????????????? <alf:label>
娛樂新聞</alf:label>
??????????????????? </xs:appinfo>
??????????????? </xs:annotation>
??????????? </xs:enumeration>??????????
??????????? <xs:enumeration value="channel03">
??????????????? <xs:annotation>
??????????????????? <xs:appinfo>
??????????????????????? <alf:label>
體育新聞</alf:label>
??????????????????? </xs:appinfo>
??????????????? </xs:annotation>
??????????? </xs:enumeration>??????????
??????? </xs:restriction>
??? </xs:simpleType>
</xs:schema>
?
上面的
下拉框是靜態的,要想自定義,
則可以在news.xsd中include一個jsp,在jsp中包含所需要的xsd代碼。
?
現在我們自定義一個下拉框,創建一個新的webform,例如名稱為channel-list,使用channel-list.xsd:
<?xml version="1.0"?>
<
xs:schema
xmlns:xs
="
http://www.w3.org/2001/XMLSchema
"
xmlns:cm
="
http://www.lively.com/alfresco/cm
"
targetNamespace
="
http://www.lively.com/alfresco/cm
"
elementFormDefault
="
qualified
">
???
<
xs:element
name
="
select_list
">
???????
<
xs:complexType
>
???????????
<
xs:sequence
>
???????????????
<
xs:element
name
="
options
"
maxOccurs
="
unbounded
">
???????????????????
<
xs:complexType
>
???????????????????????
<
xs:sequence
>
???????????????????????????
<
xs:element
name
="
value
"
type
="
xs:normalizedString
"/>
???????????????????????????
<
xs:element
name
="
label
"
type
="
xs:normalizedString
"/>
???????????????????????????
<
xs:element
name
="
description
"
type
="
xs:normalizedString
"/>
???????
???????????????
</
xs:sequence
>
???????????????????
</
xs:complexType
>
???????????????
</
xs:element
>
???????????
</
xs:sequence
>
???????
</
xs:complexType
>
???
</
xs:element
>
</
xs:schema
>
?
?
使用這個webform創建content,比如創建在
/content/news
目錄下,這些創建的數據就是下拉框中使用的內容,如上所示,下拉框使用value/label/description三個元素。則可以使用一個get_channel_list.jsp來取得這些創建的下拉框列表:
<
jsp:root
version
="
1.2
"
???????? xmlns:jsp
="
http://java.sun.com/JSP/Page
"
???
?xmlns:c
="
http://java.sun.com/jsp/jstl/core
"
???
?xmlns:cm
="
http://www.lively.com/alfresco/cm
">
??
?
<
jsp:directive.page
language
="
java
"
contentType
="
text/html; charset=UTF-8
"/>
?
<
jsp:directive.page
isELIgnored
="
false
"/>
?
???
?
<
c:set
var
="
path
"
value
="
${param['path']}
"/>
???
?
???
?
<
c:if
test
="
${empty path}
">
???
?
??
<
c:set
var
="
path
"
value
="
/content/news
"/>
???
?
</
c:if
>
???
?
???
?
<
c:set
var
="
contentType
"
value
="
${param['ctype']}
"/>
???
?
???
?
<
c:if
test
="
${empty contentType}
">
???
?
??
<
c:set
var
="
contentType
"
value
="
channel-list
"/>
???
?
</
c:if
>
???
?
?
<
xs:schema
xmlns:xs
="
http://www.w3.org/2001/XMLSchema
"
??????????? xmlns:alf
="
http://www.alfresco.org
"
?
??
??? elementFormDefault
="
qualified
">
??
<
xs:simpleType
name
="
select_list_choices
">
????
<
xs:restriction
base
="
xs:normalizedString
">
??????
<
c:forEach
items
="
${cm:getSelectList(pageContext,contentType,path)}
"
var
="
options
">
????????
<
jsp:element
name
="
xs:enumeration
">
???????????
<
jsp:attribute
name
="
value
"><
c:out
value
="
${options.value}
"/></
jsp:attribute
>
???????????
<
jsp:body
>
???????????
?
<
xs:annotation
>
???????????????
<
xs:appinfo
>
???????????????????
?
<
alf:label
><
c:out
value
="
${options.label}
"/></
alf:label
>
???????????????????
</
xs:appinfo
>
???????????
?
</
xs:annotation
>
???????????
</
jsp:body
>
???????
?
</
jsp:element
>
??????
</
c:forEach
>
????
</
xs:restriction
>
??
</
xs:simpleType
>
?
</
xs:schema
>
</
jsp:root
>
?
上面的cm標簽是我們自己定義的,可以參看附件(注意:可以在http://forge.alfresco.com/projects/wsf/上下載wsf1.5最新源碼)。
?
最后,在xsd中引入這個get_channel_list.jsp:
<
xs:include
schemaLocation
="
/
get_channel_list.jsp
"/>
……
<
xs:element
name
="
channel
"
type
="
news:
select_list_choices
"/>
……
?
這樣一個自定義的下拉框就可以實現了。
?
附:
alfresco
比較重要的幾個地址
官方wiki:
http://wiki.alfresco.com/wiki/Main_Page
論壇
:
http://forums.alfresco.com/
官方
forge
:
http://forge.alfresco.com/
alfresco
下載地址
:
http://sourceforge.net/project/showfiles.php?group_id=143373
?
alfresco WCM在表單中自定義下拉框.pdf
下載地址:
alfresco WCM在表單中自定義下拉框.rar
使用的代碼下載地址:
alfresco WCM在表單中自定義下拉框_source.rar
?
版權所有:(xiaodaoxiaodao)藍小刀
??
xiaodaoxiaodao@gmail.com