开发者

JSF 2.0 - Convert view ID to URL

开发者 https://www.devze.com 2023-03-31 09:40 出处:网络
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 act

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)}">
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号