JSF input example

From sheep
Revision as of 21:31, 14 September 2021 by Martin (talk | contribs) (Created page with "<pre> <html> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="core" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="jhtml" %> <core:view> <he...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
 <html>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="core" %>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="jhtml" %>
    <core:view>
       <head>
          <title>title</title>
       </head>
       <body>
          <jhtml:form>
             <p>Enter name</p>
 			<p>
              <jhtml:inputText value="#{user.name}"/><br/> <!-- object user property name -->
              <jhtml:commandButton value="Submit" action="addPerson"/> 
             </p>
          </jhtml:form>
       </body>
    </core:view>
 </html>

faces-config.xml

 <navigation-rule>
   <from-view-id>/start.jsp</from-view-id>
   <navigation-case>
     <from-outcome>addPerson</from-outcome>
     <to-view-id>/added.jsp</to-view-id>
   </navigation-case>
 </navigation-rule>

 <managed-bean>
   <managed-bean-name>user</managed-bean-name>
     <managed-bean-class>
       org.sheep.UserBean
     </managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>

web.xml - not need to map .faces to FacesServlet

 <servlet>
   <servlet-name>FacesServlet</servlet-name>
   <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
 </servlet>
 
 <servlet-mapping>
   <servlet-name>FacesServlet</servlet-name>
   <url-pattern>*.faces</url-pattern>
 </servlet-mapping>

If using .jsf need to map these to the jsp engine:

 <servlet-mapping>
   <servlet-name>jsp</servlet-name>
   <url-pattern>*.jsf</url-pattern>
 </servlet-mapping>