一个简单的Portal项目的建立

本文是基于Weblogic的Portal,系统为Linux
一 首先需要安装Weblogic和专用的Eclipse,安装了portal103_linux32.bin后里面会有个自带的Eclipse。
二 打开自带的Eclipse,建立一个EAR项目
三 将Weblogic的服务添加进去
四 在EAR项目下建立一个Portal web项目
五 在EAR项目下建立一个Datasync项目
六 进入Portal web项目在webcontent下面建一个Portal,然后任意建一个JSP页面,建立的JSP页面必须是JSF的,将其html,body,title,head标签全部删除,将其放入Portal中,按照提示建立portlet。
七 再写两个JSP页面,用于页面间人跳转,然后修改配置文件faces-config.xml,配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
    version="1.2">
	<navigation-rule>
		<from-view-id>/firstpage.jsp</from-view-id>
		<navigation-case>
                        <!-- 当得到testtwo返回值时,从firstpage.jsp转向secondepage.jsp -->
			<from-outcome>testtwo</from-outcome>
			<to-view-id>/secondpage.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	<navigation-rule>
		<from-view-id>/firstpage.jsp</from-view-id>
		<navigation-case>
			<from-outcome>testthree</from-outcome>
			<to-view-id>/thirdpage.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
</faces-config>

当然这步可以通过视图完成,打开faces-config.xm,选择Navigation rules就可以操作
八 写个简单的类进行测试,我写的测试类如下:
public class Testportal {
	private String strone;
	private String strtwo;
	public String getStrone() {
		return strone;
	}
	public void setStrone(String strone) {
		this.strone = strone;
	}
	public String getStrtwo() {
		return strtwo;
	}
	public void setStrtwo(String strtwo) {
		this.strtwo = strtwo;
	}
	public String strcompare(){
		if(strone.equals(strtwo)){
			return "testtwo";
		}
		return "testthree";
	}
}

当然这个类要和我们的portal联系起来,打开faces-config.xml文件,选择manageben,选择request添加,然后找到你要关联的类,添加,我这里用testportalbean。成功后的faces-config.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
    version="1.2">
        <!-- 这里为刚添加的内容 managed-bean -->
	<managed-bean>
		<managed-bean-name>testcreatebean</managed-bean-name>
		<managed-bean-class>com.Testcreate</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>
	<navigation-rule>
		<from-view-id>/firstpage.jsp</from-view-id>
		<navigation-case>
			<from-outcome>testtwo</from-outcome>
			<to-view-id>/secondpage.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	<navigation-rule>
		<from-view-id>/firstpage.jsp</from-view-id>
		<navigation-case>
			<from-outcome>testthree</from-outcome>
			<to-view-id>/thirdpage.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
</faces-config>

九 编写firstpage.jsp,让其与我们写的类联系,我的页面如下,很简单:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<f:view>
        Put your faces content here<br/>
        <!-- 表单 -->
        <h:form>
                <!-- 文本框,对应到关联的类的属性上,testcreat
        	<h:inputText value="#{testprotalbean.strone}"></h:inputText>
        	<h:inputText value="#{testportalbean.strtwo}"></h:inputText>
        	<br />
        	<h:commandButton action="#{testprotalbean.strcompare}" value="submit"></h:commandButton>
        </h:form> 
</f:view>

然后保存发布,基本就完成了

你可能感兴趣的:(eclipse,jsp,xml,weblogic,JSF)