JEE JavaServer Faces

De Wiki de Romain RUDIGER
Aller à : navigation, rechercher
Language: English  • français

Faces Servlet Mapping

Two ways :

  • suffix mapping
  • prefix mapping

First way, content of web.xml:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern><!-- All requests on this folder are mapping on FacesServlet -->
</servlet-mapping>

The URL is of type: http://localhost:port/apppli-context/faces/installation/index.jsp


Second way, content of web.xml:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup> 1 </load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/*.jsf</url-pattern><!-- All jsf pages are mapping on FacesServlet -->
</servlet-mapping>

The URL is of type: http://localhost:port/apppli-context/installation/index.jsp

Exemples / Examples

<rich:dataTable>

<rich:dataTable> with sort and nested values (<a4j:repeat> but also possible with <h:dataTable>).

For more information about dataTable show the documentation and the The BalusC Code: Using datatables

<rich:dataTable id="userTable" onRowMouseOver="this.style.backgroundColor='#F1F1F1'"  
  onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'" 
  binding="#{userEntity.userTable}" value='#{userEntity.userList}' var='item' 
  columnClasses="center" rows="15" reRender="ds">
    <f:facet name="header">
        <h:outputText value="#{bundle.userManagement_list_title}"/>
    </f:facet>
    <rich:column sortBy="#{item.userid}" breakBefore="true">
        <f:facet name="header">
            <h:outputText value="#{bundle.userManagement_userid}"/>
        </f:facet>
        <h:outputText value=" #{item.userid}"/>
    </rich:column>
    <h:column>
        <f:facet name="header">
            <h:outputText value="#{bundle.userManagement_courriel}"/>
        </f:facet>
        <h:outputText value=" #{item.courriel}"/>
    </h:column>
    <h:column>
        <f:facet name="header">
            <h:outputText value="#{bundle.userManagement_groups}"/>
        </f:facet>
        <ul style="list-style-type:none;margin:0;padding:0;">
            <a4j:repeat value='#{userEntity.groupsByUserid}' var='item'>
                <li>
                    <h:outputText value=" #{item.groupEntityPK.groupid}"/>
                </li>
            </a4j:repeat>
        </ul>
    </h:column>
    <h:column>
        <f:facet name="header">
            <h:outputText escape="false" value="&nbsp;"/>
        </f:facet>
        <h:commandButton action="#{userEntity.editUserForm}" image="/img/edit22.png" alt="#{bundle.userManagement_user_edit}"/>

        <h:commandButton action="#{userEntity.removeUserForm}" image="/img/delete22.png" alt="#{bundle.userManagement_user_remove}"/>
    </h:column>
    <f:facet name="footer">
        <rich:datascroller id="userTable"></rich:datascroller>
    </f:facet>
</rich:dataTable>
<h:commandButton action="#{userEntity.createForm}" image="/img/adduser22.png" alt="#{bundle.userManagement_user_add}"/>
&nbsp;
<a4j:commandButton action="#{userEntity.refresh}" image="/img/refresh22.png" alt="#{bundle.userManagement_refresh}" reRender="UserManagement"/>

<rich:poll>

Make ajax requests to the server and update the page. In this example you have an iteration on an object list (<a4j:repeat>) :

<h:panelGroup id="LightView">
    <h:form id="LightViewPoll">
        <a4j:poll id="poll" interval="#{main.pollInterval}" enabled="#{main.pollEnabled}" reRender="lightsStatus" />
    </h:form>
    <h:form id="LightViewForm">
        <div id="HRlist">
            <ul>
                <a4j:repeat id="lightsStatus" value="#{lightsStatus.lightList}" var="light" binding="#{lightsStatus.repeater}">
                    <li>
                        <rich:panel header="#{light.name}" bodyClass="lightsStatusBody">
                            <h:outputText value="#{light.status}"/>
                            <br/>
                            <a4j:commandButton value="switch on" action="#{lightsStatus.switchOn}" rendered="#{lightsStatus.canSwitchOn}"/>
                            <a4j:commandButton value="switch off" action="#{lightsStatus.switchOff}" rendered="#{not lightsStatus.canSwitchOn}"/>
                        </rich:panel>
                    </li>
                </a4j:repeat>
            </ul>
        </div>
    </h:form>
</h:panelGroup>