PrettyFace mapping servlet by annotation and use h:link

Splash Forums PrettyFaces Users PrettyFace mapping servlet by annotation and use h:link

This topic contains 3 replies, has 3 voices, and was last updated by  Christian Kaltepoth 10 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #18068

    Pozoga
    Participant

    Hi.

    I am new user of the forum and beginner in prettyface. I using annotation to mapping ma servlet. It work but when i use h:link, the link isn’t generate :(

    My servlet code:

    @WebServlet(urlPatterns={“/WEB-INF/servlet/test1.do”})

    @URLMapping(id = “test”, pattern = “/test/”, viewId = “/WEB-INF/servlet/test1.do”)

    public class Test extends HttpServlet {

    /**

    * Processes requests for both HTTP GET and POST methods.

    * @param request servlet request

    * @param response servlet response

    * @throws ServletException if a servlet-specific error occurs

    * @throws IOException if an I/O error occurs

    */

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

    request.getRequestDispatcher(“/test.xhtml”).forward(request, response);

    }

    // <editor-fold defaultstate=”collapsed” desc=”HttpServlet methods. Click on the + sign on the left to edit the code.”>

    /**

    * Handles the HTTP GET method.

    * @param request servlet request

    * @param response servlet response

    * @throws ServletException if a servlet-specific error occurs

    * @throws IOException if an I/O error occurs

    */

    @Override

    protected void doGet(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

    processRequest(request, response);

    }

    /**

    * Handles the HTTP POST method.

    * @param request servlet request

    * @param response servlet response

    * @throws ServletException if a servlet-specific error occurs

    * @throws IOException if an I/O error occurs

    */

    @Override

    protected void doPost(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

    processRequest(request, response);

    }

    /**

    * Returns a short description of the servlet.

    * @return a String containing servlet description

    */

    @Override

    public String getServletInfo() {

    return “Short description”;

    }// </editor-fold>

    }

    My test jsf view:

    <ui:composition

    template=”#{theme.scriptPath}”

    xmlns:h=”http://java.sun.com/jsf/html”

    xmlns:f=”http://java.sun.com/jsf/core”

    xmlns:ui=”http://java.sun.com/jsf/facelets”

    xmlns:c=”http://java.sun.com/jsp/jstl/core”

    xmlns:p=”http://jspf.pozoga.eu/jstl”

    xmlns:pretty=”http://ocpsoft.com/prettyfaces”>

    <ui:define name=”content”>

    <pretty:link mappingId=”test”>Link</pretty:link>

    <h:link outcome=”pretty:test”>Test2</h:link>

    </ui:define>

    </ui:composition>

    And html result is:

    Link<span>: This link is disabled because a navigation case could not be matched.Test2</span>

    A first link is ok, but second (generated with h:link) don’t work.

    When I mapping a jsf file it work good, but when a mapping servlet don’t work. Someone know why?

    #21614

    Hi @pozoga,

    What you are trying to do is mix JSF navigation with a Servlet Mapping. The problem is that JSF doesn’t know about Servlets. Because you are using the <h:link> to try to link to a servlet, JSF does not know about the servlet. Try with the <pretty:link> component instead, it directly creates the link based on your configuration, and does not try to go through JSF like the native <h:link> component.

    http://ocpsoft.com/docs/prettyfaces/3.3.0/en-US/html_single/#components.prettylink

    Let me know if this works better.

    Thanks!

    ~Lincoln

    #21615

    Pozoga
    Participant

    Yes, pretty:link work but I wanted to use h:link. If it isn’t possible I will use pretty:link.

    Thanks :)

    #21616

    Hi,

    I agree with Lincoln. h:link won’t work if you want to use it with a servlet. You should really use pretty:link for this. And pretty:link renders a HTML link exactly like h:link, so it will be OK for you to use it.

    Christian

Viewing 4 posts - 1 through 4 (of 4 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.