Generating a link dynamically with urlrewrite - jsf

I am using urlrewriting and my pattern matches ../products/product_id and maps to /product.jsf?product_id=$1.
The rewriting performs well, but I am having trouble generating dynamic links.
In a context of iteration:
...
<h:link value="view product" outcome="products/#{item.id}"/>
...
The case is very simple. I just want the url generated has the form "products/123", but the page doesn't render, I guess because the outcome cannot be resolved at generation time.
I could just generate a link with "/product.jsf" and add a view parameter. But I prefer the other way. How can I have this behavior?

If you don't have a valid navigation case outcome, just use plain HTML <a>.
view product
Depending on the current URI, you may only need to prepend the context path yourself.
view product

Related

Kentico 9 transformation page/file URL

In my custom page type, you can select an uploaded file. That's fine, but in my ascx transformation, i'm having a hard time getting the URL. The field is 'Process'.
Here's what i currently have.
<%# IfEmpty(Eval("Process"),"N/A","<a href=" + Eval("Process") +" target='blank' class='icon download'>Download</a>")%>
When rendered, the html is this:
Download
I'm missing something.
You can use either of the 2 methods below. Both have their downfalls though.
<a href="<%# GetFileUrl("Process", "Something") %>"Link here<a/> this will
Downfall with this is if there is no value in the "Process" field, it will return an invalid URL. So I tend to use something a little better (but not much)
Item to download
This will create a valid URL with some invalid properties to it. Meaning if there is no value in the Process field, it will return 00000000-0000-0000-0000-000000000000. If the NodeAlias field is empty, it will return "download". So again, not 100% fool-proof but it works well in most cases.
Update
Check out this link:
https://devnet.kentico.com/articles/options-for-file-fields-in-structured-data
I think the piece you need in here is in the "CMS.File page type" section:
This is the link to the picture
Check out transformation methods reference
You can use <%#GetImage(Eval("Process"))%>. This will return an Image tag. There are a couple other parameters for sizing if you want to use those.
See the "Transformation reference" link on your Trasnformation editor, it goes to all the available transformation methods you can use.
In it it shows:
This will generate an actual image tag. If however you want a link, it usually is
/getattachment/<%# Eval("TheImage")%>/ImageFileNameCanBeAnythingThough.jpg
example:
/getattachment/1936c69d-a28c-428a-90a7-09154918da0f/Christmas.jpg

URL rewriting in primefaces

I want to hide the xhtml page name when redirecting, url should be user defined. For All redirecting pages the URL should be same only the content of the page should be changed. how i need to implement this in primefaces without using third party tool like pretty faces.
First of all, what you are talking about is not URL rewriting.
By 'URL Rewriting' we mean to show more user friendly URL instead the one your page already have.
If what you want to achieve is to have only one URL for all of your pages, maybe your should use ui:include with rendered tag for every page in your home page and keep your page name in session scoped bean, which is BAD idea and NOT a good practice.
More of this is explained here:
How to include another XHTML in XHTML using JSF 2.0 Facelets?
and what you need to add is this:
<ui:include src=".../PageOne.xhtml" rendered="#{mySessionBean.pageToShow.equalsIgnoreCase('PageOne')}" >
Anyway I don't really see any security based reason why would you need to do this. Maybe you are looking for an answer in a wrong direction.
I will let you decide if you need this or not.

JSF OutputText with html style

I need a output text which works like h:outputText with escape="false" attribute, but doesn't let scripts to run. After a little search I found tr:outputFormatted makes that, but in our project we doesn't use trinidad. Is there something like outputFormatted in tomahawk, or in another taglib?
for example,
<h:outputText id="id" value="<b>test text</b><script type="text/javascipt">alert('I dont want these alert to show');</script>" escape="false"/>
that shows 'test text' bold but it popups the alert dialog too, I don't want the script to run. it can write script code or delete it but shouldn't run.
Use a HTML parser to get rid of those malicious things.
Among others, Jsoup is capable of this. Here's an extract of relevance from its site.
Sanitize untrusted HTML
Problem
You want to allow untrusted users to supply HTML for output on your website (e.g. as comment submission). You need to clean this HTML to avoid cross-site scripting (XSS) attacks.
Solution
Use the jsoup HTML Cleaner with a configuration specified by a Whitelist.
String unsafe =
"<p><a href='http://example.com/' onclick='stealCookies()'>Link</a></p>";
String safe = Jsoup.clean(unsafe, Whitelist.basic());
// now: <p>Link</p>
So, all you basically need to do is the the following during preparing the text:
String sanitizedText = Jsoup.clean(rawText, Whitelist.basic());
(you can do it before or after saving the text in DB, but keep in mind that when doing it before without saving the original text, you can't detect malicious users and do social actions anymore)
and then display it as follows:
<h:outputText value="#{bean.sanitizedText}" escape="false" />

JSF to set style in stylesheets?

So I'm trying to create a webpage with customizable style for each user. You can save style options as strings in a JSF bean property and access them in inline style attributes, or <style> tags within a webpage very easily, but who uses inline/onpage styling anymore?
Is there any way to forward these properties from a JSF (2.0) bean to my stylesheet or am I required to simply add <style> blocks to the pages I wish to be customizable?
EDIT: I guess I could make a function to write these properties to a stylesheet, making one for each user, but this is obviously not preferred.
For full customization, you could save stylesheets for all the changeable elements and their style options and reference these with your bean properties.
Since that is quite a bit of stylesheets though, you could just define your own style schemes and give the users a choice between these pre-defined stylesheets. This doesn't exactly answer your question but would save a lot of work
I'm not sure exactly what your functionality is, but one option would be ->
<h:outputStylesheet library="css" name="#{userBean.styleSheetName}" />
Where the "UserBean" had names of sheets.
Alternatively you could just output the stylesheet (as you said) inbetween the style tags. If you wanted to go nuts you could write a servlet that read the user's session and generated a cached stylesheet.
I would definitely go the servlet route for the functionality you're suggesting, but if it is just a "set" of stylesheets the users have access to, I would probably use a simple dynamic property as per the first example.

Contents of h:head are not getting updated while using template in JSF (ICEFACES)

Requirement:
Adding javascript file for a given page (which uses templates).
Details:
After successful login, user is navigated to a page, where he can perform different actions.
I have used common template in all the pages (apart from login page).
The template contains head tag, code for including header, footer and body (in which dynamic content will be included).
I observed that contents of head tag of the template are not getting updated (i.e. title tag, script tag).
The contents of head tag remains same as that of login page and also the URL of my browser.
Can you please let me know the possible cause for above.
It is probably related to the fact partial updates require id of a tag to be updated and html head element does not support id. There is no address in the html to apply update to. Icefaces are using partial updates heavily. You can try to enforce full update upon interaction which triggers changes to head element.

Resources