I want to con开发者_如何学Pythonvert a view ID into a URL using EL.
The purpose of doing this is to use an html <form/>
tag to submit a form to a page using GET
instead of POST
. The form's action
attribute needs to have a URL, unlike <h:form/>
.
You can use #{request.contextPath}
to dynamically inline the context path:
<form action="#{request.contextPath}/some.xhtml">
If you want to submit to the current view ID, get it by #{facesContext.viewRoot.viewId}
:
<form action="#{request.contextPath}#{facesContext.viewRoot.viewId}">
Or if you haven't mapped the FacesServlet
on *.xhtml
for some reason, or you don't want to be dependent on its mapping and your container supports EL 2.2 (or JBoss EL), then use ViewHandler#getActionURL()
instead:
<form action="#{facesContext.application.viewHandler.getActionURL(facesContext, view.viewId)}">
This writes the outbound URL from a view ID via the servlet container in a single step:
<form action="#{facesContext.application.viewHandler.getBookmarkableURL(facesContext,view.viewId,null,false)}">
精彩评论