posts - 12, comments - 4, trackbacks - 0, articles - 0

JSF入门

Posted on 2007-11-08 22:29 Edward's 阅读(185) 评论(0)  编辑  收藏 所属分类: JSF

1、加载jsf的包

2、javaBean中

class:org.edward.Mybean,

porperty:[double firstNumber,double secondNumber,double result];

method:public String add(){result = firstNumber + secondNumber;return "suceess";}

3、jsp页面,以jsf为模板创建jsp文件

add.jsp

<h:form>
    <h:panelGrid columns="3">
        <h:outputLabel value="请输入第一个数字"></h:outputLabel>
        <h:inputText id="firstNumber" value="#{myBean.firstNumber}"></h:inputText>
        <h:message for="firstNumber"></h:message>
        <h:outputLabel value="请输入第二个数字"></h:outputLabel>
        <h:inputText id="secondNumber" value="#{myBean.secondNumber}"></h:inputText>
        <h:message for="secondNumber"></h:message>
    </h:panelGrid>
    <h:commandButton value="加" action="#{myBean.add}"></h:commandButton>
</h:form>

result.jsp

<h:inputText value="#{myBean.result}"></h:inputText>

4、faces-config.xml

<managed-bean>
        <managed-bean-name>myBean</managed-bean-name>
        <managed-bean-class>org.edward.MyBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <from-view-id>/add.jsp</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/success.jsp</to-view-id>
        </navigation-case>
    </navigation-rule

 

只有注册用户登录后才能发表评论。


网站导航: