Use of h:form in Facelets files in /WEB-INF opened by RequestDispatcher#forward() to execute methods of managed beans

梦想的初衷 提交于 2019-12-12 03:13:17

问题


I'm using Java EE for an enterprise application on Glassfish.

I have some xhtml files in WEB-INF to prevent direct URL access, that I can access using a servlet. I need to call a method of a managed bean when the user press a button.

The xhtml code I'm using is:

<h:form><p:commandButton action="#{managedBean.testFunction()}" value="Test function" type="submit" ajax="false" styleClass="block" /></h:form>

The problem is that the input of h:form seems to redirect me to the actual path to my xhtml file, e.g.:

My servlet mapped at:

/ServlerDispatcher/DispatcherServlet

using:

request.getRequestDispatcher("/WEB-INF/HiddenFiles/fileA.xhtml").forward(request, response);

displays the xhtml file in the WEB-INF folder, that contains the form I mentioned above. Submitting the form, by pressing the button redirects me to this URL:

/ServlerDispatcher/WEB-INF/HiddenFiles/fileA.xhtml`` 

that cannot be displayed since it's in the WEB-INF folder to prevent direct URL access.

As I said what I really need is execute a managed bean method when the user press a button. How can I do that?

Thanks for your attention

来源:https://stackoverflow.com/questions/28036049/use-of-hform-in-facelets-files-in-web-inf-opened-by-requestdispatcherforward

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!