天天看点

ofbiz实战——教师管理实现代码

ofbiz项目开发主要代码模块:

1.配置controller.xml。(具体路径:hot-deploy\booking\webapp\booking\WEB-INF目录下)

        只有配置了controller.xml才能对用户的请求进行映射处理。

2.配置XXXScreens.xml与XXXForms.xml。(所在目录:hot-deploy\booking\widget\booking)

        配置上面2个文件可以实现界面的控件以及布局。如果有些地方不好布局,可以使freemarker模板技术,通过ftl文件布局。

3.配置service和entity。

        这个主要配置services.xml,secas.xml,eecas.xml。通过配置上面文件实现控制后台业务逻辑处理流程。

4.业务逻辑实现。

        编写脚本,或者java类实现业务逻辑。

第1,3点内容我都放如  ofbiz实战——实验室预约系统共用配置文件  中了,具体可以参考里面的配置。下面主要贴一下第2和4点的配置以及实现。

配置TeacherScreens.xml

<?xml version="1.0" encoding="UTF-8"?>
<screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://ofbiz.apache.org/Widget-Screen" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Screen http://ofbiz.apache.org/dtds/widget-screen.xsd">
	<screen name="FindTeacher">
        <section>
            <actions>
                <set field="titleProperty" value="TchInfoManange"/>
				<set field="headerItem" value="TchInfoManange"/>
                <set field="viewIndex" from-field="parameters.VIEW_INDEX" type="Integer"/>
                <property-to-field resource="widget" property="widget.form.defaultViewSize" field="viewSizeDefaultValue"/>
                <set field="viewSize" from-field="parameters.VIEW_SIZE" type="Integer" default-value="${viewSizeDefaultValue}"/>
            </actions>
            <widgets>
                <decorator-screen name="CommonBookingDecorator" location="component://booking/widget/booking/CommonScreens.xml">
                    <decorator-section name="body">
                        <section>
                            <widgets>
                                <decorator-screen name="FindScreenDecorator" location="component://common/widget/CommonScreens.xml">
                                    <decorator-section name="menu-bar">
                                        <container style="button-bar">
                                            <link target="EditTeacher" text="${uiLabelMap.EditTeacher}" style="buttontext"/>
                                        </container>
                                    </decorator-section>
                                    <decorator-section name="search-options">
                                        <include-form name="FindTeacher" location="component://booking/widget/booking/TeacherForms.xml"/>
                                    </decorator-section>
                                    <decorator-section name="search-results">
                                        <include-form name="ListFindTeacher" location="component://booking/widget/booking/TeacherForms.xml"/>
                                    </decorator-section>
                                </decorator-screen>
                            </widgets>
                        </section>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
	<screen name="EditTeacher">
        <section>
            <actions>
                <set field="titleProperty" value="TchInfoManange"/>
                <set field="headerItem" value="TchInfoManange"/>
				<entity-one entity-name="Teacher" value-field="teacher"/>
            </actions>
            <widgets>
                <decorator-screen name="CommonBookingDecorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
						<container style="button-bar">
							<link target="FindTeacher" text="${uiLabelMap.CommonBack}" style="buttontext"/>
						</container>
                        <screenlet title="${groovy: parameters.tchId ? uiLabelMap.CommonEdit : uiLabelMap.CommonAdd}">
                            <include-form name="EditTeacher" location="component://booking/widget/booking/TeacherForms.xml"/>
                        </screenlet>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
	<screen name="LookupTeacher">
        <section>
            <actions>
                <property-map resource="BookingUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="title" value="${uiLabelMap.PageTitleLookupTeacher}"/>
                <set field="queryString" from-field="result.queryString"/>
                <set field="entityName" value="Teacher"/>
                <set field="searchFields" value="[tchId, name]"/>
            </actions>
            <widgets>
                <decorator-screen name="LookupDecorator" location="component://common/widget/CommonScreens.xml">
                    <decorator-section name="search-options">
                        <include-form name="LookupTeacher" location="component://booking/widget/booking/TeacherForms.xml"/>
                    </decorator-section>
                    <decorator-section name="search-results">
                        <include-form name="ListLookupTeacher" location="component://booking/widget/booking/TeacherForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
</screens>
           

配置TeacherForms.xml

<?xml version="1.0" encoding="UTF-8"?>

<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd">
    
    <form name="FindTeacher" target="FindTeacher" title="" type="single"
        header-row-style="header-row" default-table-style="basic-table">
        <field name="name" title="${uiLabelMap.BookingName}"><text-find/></field>
        <field name="submitButton" title="${uiLabelMap.CommonFind}"><submit/></field>
    </form>

    <form name="ListFindTeacher" list-name="listIt" title="" type="list" paginate-target="FindTeacher"
        odd-row-style="alternate-row" default-table-style="basic-table hover-bar">
        <actions>
            <service service-name="performFind" result-map="result" result-map-list="listIt">
                <field-map field-name="inputFields" from-field="requestParameters"/>
                <field-map field-name="entityName" value="Teacher"/>
                <field-map field-name="viewIndex" from-field="viewIndex"/>
                <field-map field-name="viewSize" from-field="viewSize"/>
				<field-map field-name="noConditionFind" value="Y"/>
            </service>
        </actions>
        <field name="tchId" title="${uiLabelMap.BookingTeacherTchId}"><display/></field>
		<field name="name" title="${uiLabelMap.BookingName}"><display/></field>
        <field name="deptName" title="${uiLabelMap.BookingTeacherDeptName}"><display/></field>
		<field name="sex" title="${uiLabelMap.BookingSex}">
			<display description="${groovy: sex == 'Male' ? uiLabelMap.CommonMale : (sex == 'Female' ? uiLabelMap.CommonFemale : ' ')}"/>
		</field>
		
		<field name="updateLink" title=" " widget-style="buttontext">
            <hyperlink description="${uiLabelMap.CommonUpdate}" target="EditTeacher" >
                <parameter param-name="tchId"/>
            </hyperlink>
        </field>
        <field name="deleteLink" title=" " widget-style="buttontext">
            <hyperlink description="${uiLabelMap.CommonDelete}" target="deleteTeacher" also-hidden="false">
                <parameter param-name="tchId"/>
            </hyperlink>
        </field>
        
    </form>
	
	<form name="EditTeacher" target="updateTeacher" title="" type="single" header-row-style="header-row" 
		default-table-style="basic-table" default-map-name="teacher" default-entity-name="Teacher">
		<alt-target use-when="teacher==null" target="createTeacher"/>
		<auto-fields-service service-name="updateTeacher" map-name=""/>
		<field use-when="teacher!=null" name="tchId" title="${uiLabelMap.BookingTeacherTchId}" tooltip="${uiLabelMap.BookingNotModification}." ><display/></field>
        <field use-when="teacher==null" name="tchId" title="${uiLabelMap.BookingTeacherTchId}" required-field="true"><text size="20" maxlength="20" /></field>
        <field name="name" title="${uiLabelMap.BookingName}" required-field="true"><text size="20" maxlength="20" /></field>
		<field name="deptName" title="${uiLabelMap.BookingTeacherDeptName}" ><text size="20" maxlength="20" /></field>
		<field name="sex" title="${uiLabelMap.BookingSex}">
            <drop-down allow-empty="false" >
				<option key="Male" description="${uiLabelMap.CommonMale}"/>
                <option key="Female" description="${uiLabelMap.CommonFemale}"/>
            </drop-down>
        </field>
        <field name="submitButton" title="${uiLabelMap.CommonSubmit}">
			<submit/>
		</field>
    </form>
	
	<form name="LookupTeacher" target="LookupTeacher" title="" type="single"
        header-row-style="header-row" default-table-style="basic-table">
        <!-- <auto-fields-entity entity-name="Teacher" default-field-type="hidden"/> -->
        <field name="name" title="${uiLabelMap.BookingTeacherName}"><text-find/></field>
        <field name="submitButton" title="${uiLabelMap.CommonFind}"><submit/></field>
    </form>
    <form name="ListLookupTeacher" list-name="listIt" title="" type="list" paginate-target="LookupTeacher"
        odd-row-style="alternate-row" default-table-style="basic-table" view-size="20">       
		<actions>
            <service service-name="performFind" result-map="result" result-map-list="listIt">
                <field-map field-name="inputFields" from-field="requestParameters"/>
                <field-map field-name="entityName" value="Teacher"/>
                <field-map field-name="viewIndex" from-field="viewIndex"/>
                <field-map field-name="viewSize" from-field="viewSize"/>
				<field-map field-name="noConditionFind" value="Y"/>
            </service>
        </actions>
		<field name="tchId" title="${uiLabelMap.BookingTeacherId}" widget-style="buttontext">  
			<hyperlink description="${tchId}" target="javascript:set_value('${tchId}')" also-hidden="false" target-type="plain"/>  
		</field>
        <field name="name" title="${uiLabelMap.BookingTeacherName}"><display/></field>
    </form>
</forms>
           

教师信息管理由于是使用的ofbiz自带的entity-auto引擎实现的实体的增删改查,所以没有相关的业务实现代码。

返回导航页

继续阅读