JSF page in subfolder can't see template - jsf-2

I've got a template in WEB-INF/templates/standardTemplate.xhtml
In my "Web Pages" root, I've got an index.xhtml which uses the template via
<ui:composition template="/WEB-INF/templates/standardTemplate.xhtml">
The above works fine.
However I also have another page which uses the same template, but it's in a subfolder "Web Pages"/messageboard/list.xhtml
It uses exactly the same syntax/paths:
<ui:composition template="/WEB-INF/templates/standardTemplate.xhtml">
But it can't find the template and renders just the content of list.xhtml (none of the template's content).
Faces servlet is mapped to "/faces/*"
What am I doing wrong? Tried every variant I can think of but I can't get the right syntax.
Thanks

As per the comments, you're seeing <ui:composition> unparsed in the HTML output.
That can only mean that the request URL as you've in the browser address bar does not match the URL pattern of the FacesServlet. Make sure that it matches the URL pattern of the FacesServlet. You've mapped it on /faces/*, so the URL should contain the /faces path prefix right after the context path.
Better would be to map the FacesServlet directly on *.xhtml so that you never need to fiddle with virtual URLs.

Related

Primefaces fileUpload change POST URI

I'm using PrimeFaces 6 fileUpload component along with a URL rewrite framework.
So that, http requests to: domain/URI/fileupload are routed to: domain/OTHER_URI/upload.xhtml
I submit this with a different commandButton as javascript PF('fileUploadWidget').submit();
When the file is POSTed to the server, it's using the wrong path (OTHER_URI/upload.xhtml) and failing.
I've tried locating and changing this in the javascript widgetvar object as well as the form on the page, but it still POSTs to the wrong URI. How can I change the URL where PrimeFaces fileupload submits?
Thank you
I was able to resolve my issue by changing the URL rewrite configuration.
I was mapping /fileUpload to a path in WEB-INF. This caused POSTs to an unreachable location. Instead of trying to change the POST URL, I mapped to an accessible path, outside of WEB-INF.

How to include another XHTML in XHTML with path info in URL

I will post some pictures to clarify my problem.... i WOULD post pictures but i am not allowed to -.-
If i use a url like
localhost:8080/SupervoteWeb/polls
everything works fine. The header is displayed correctly.
But for some sites i need the url for passing ids or other attributes.
I have checked if it is because of this parameter passing. This is not the case.
An URL like:
localhost:8080/SupervoteWeb/polls[/ enter anything here]
always leads to an error where the header is not displayed correctly.
This is the code of the header. It is placed on every site.
<ui:insert>
<ui:include src="/protected/header.xhtml" />
</ui:insert
By the way: I am using prettyfaces for clean urlmappings.
Can you tell me where this weird behaviour comes from?
If there is any code missing you may need i will post it.
The problem is solved!
The .css was not found - I had relative links to my css files.

CommandLink action redirect to external url not working

I am using jsf 2. I have a link in a facelet file that points to a external url. My current view is /app1/home.xhtml with a h:commandLink that has an action like so
<h:commandLink value="#{link}" action="#{action.redirect}" target="_blank"/>
the url that action.redirect redirects to is /app2/info.do. However it appears that JSF tries to change the extension of the url to .xhtml. and then fails with the error message.
com.sun.faces.context.FacesFileNotFoundException: /app2/info.xhtml Not Found in ExternalContext as a Resource
how do i get this to correctly redirect ?
Don't use the <h:commandLink> here, it's the wrong tag for the purpose. It is designed to submit a JSF POST form and navigate to a JSF view, both which you obviously don't want to let take place in this particular use case.
Just use the <h:outputLink> or even plain HTML <a>. So,
<h:outputLink value="#{action.redirect}" target="_blank">#{link}</h:outputLink>
or
#{link}
Note that you don't need the <h:form> in both approaches.

When to use f:view and f:subview

I am not sure what are the benefits of using <f:view> and <f:subview>.
I noticed that one could write JSF pages without using them.
What are the benefits of using those tags?
<f:view>
The <f:view> is only useful if you want to explicitly specify/override any of the available attributes such as locale, encoding, contentType, etc or want to attach some phase listeners. E.g.
<f:view locale="#{user.locale}" encoding="UTF-8" contentType="text/html">
If you don't specify it, then the sane JSF defaults will just be used instead, which is respectively UIViewRoot#getLocale(), UTF-8 and the closest match of Accept request header. Noted should be that the closest match of Accept request header isn't always entirely right. Sometimes it results in application/xhtml+xml because of the presence of .xhtml extension in the URL in case of Facelets and the webbrowser not being configured to interpret it as text/html by default (like MSIE). You'd really like to avoid this wrong content type by explicitly setting it to text/html.
Note that it doesn't matter where you put it in the template. You can even put it in template client as immediate child of <ui:define>. However, canonical place is as immediate child of <html> and thus wrapping both <h:head> and <h:body>. This is also the way how it's done in legacy JSP where it's actually required. In Facelets it's optional and accounted as meta data.
See also:
Our XHTML wiki page
Is it possible to use JSF+Facelets with HTML 4/5?
JSF 2.0 not rendering any page
<f:subview>
The <f:subview> will create another naming container context. This is particularly useful when you want to reuse an include file which in turn contain fixed component IDs more than once in the same view root, otherwise you will get duplicate component ID errors. However, since JSF 2.0 such an include file can better be a composite component which is by itself already a naming container.
If you don't specify it, then it won't harm if you don't reuse a component with the same ID physically multiple times in the view.
See also:
Why <h:panelGroup> id is not found when I access through <f:subview> tag?
Binding attribute causes duplicate component ID found in the view
Difference between <f:subview> and <ui:composition> tags

ASP.NET MVC 2 parameters throws JS error

My application works fine when I have only one parameter.
e.g.
/Product/Index/2
/Report/Sales/08-2009
But it failes when I add one more part to the url. Let's say I want to add the end month-year parameter to the url routing. Mow it becomes:
/Report/Sales/05-2009/09-2009
I do get both parameters in my action method. I parse it and retrieve the data and pass the Model to the View. With this scenario it throws the client side JS error when I try to access any of the form elements. I get "object expected" error. The same view works fine using just first parameter. What could be the issues here?
I also loose the CSS styles when this error occurs.
Thanks
well, without seeing any code at all this is difficult to troubleshoot, but I'd say it's likely because you are referencing your javascript and css files using a relative path like:
../content/scripts/myjavascript.js
Adding the second url parameter has caused the browser to be unable to find the urls because you have added what looks like an extra level of depth to the url.
You should provide absolute urls to your scripts and css files. An easy way to do this is to use the "ResolveUrl" method like so:
<%= ResolveUrl("~/Content/Scripts/myjavascript.css") %>

Resources