How to add new line Character ( \n ) in message resource bundle in JSF1.2 - jsf

In my sample JSF application am using rich:dataTable in page to display data.
I have 2 header to display value in rich:dataTable like following
--------------------------------
| UserDetails | EmpoyeeDetails |
--------------------------------
In message resource bundle file having key and value like
usrDet = UserDetails
empDet = EmpoyeeDetails
I need to display like User in one line and Details in next line of that particular header
----------------------
| User | Empoyee |
| Details | Details |
---------------------
How to add new line character in message bundle between words? I tried by adding Hexadecimal code, Numerical Code for \n like
, \u000A but its not
working for me! Any Idea?

JSF generates HTML. Newlines in HTML are not represented by the \n character, but by the <br> element.
In order to have the HTML client to interpret \n too, you need to throw in CSS white-space: pre or pre-wrap:
key = Lorem ipsum.\nDolor sit amet.
<h:outputText value="#{bundle.key}" style="white-space: pre-wrap" />
Alternatively, use <br> instead and have JSF unescape it. E.g.
key = Lorem ipsum.<br/>Dolor sit amet.
<h:outputText value="#{bundle.key}" escape="false" />

Try the steps outlined here: http://www.mkyong.com/java/how-to-insert-a-new-line-in-resource-bundle-messages-java/
Basically, you use the StringEscapeUtils.unescapeJava(String str) static method.

Related

Put linebreak/newline in tooltip

I'd like to put a linebreak in a tooltip so that it displays like:
Nom: value1
Quality: value2
I tried:
1.
<h:outputText title="Nom: #{cntc.value1}<br/>Quality: #{cntc.value1}" />
2.
<h:outputText title="Nom: #{ (''.concat(cntc.value1).concat('<br/>')concat('Quality: ').concat(cntc.value2)}" />
None of them worked for me. It seems that the <br/> isn't being interpreted.
How can I achieve this?
It's not a good idea to name the problem "Concatenating strings in EL" if your issue is with neither of those things. You want to create a multi-line title, that's an HTML problem.
Title only accepts text so <br/> will not work but you can put a line break (
) in there:
<h:outputText value="#{cntc.mail }" title="Nom: #{cntc.nom}
Qualite: #{cntc.qualite}" />
Note that this may not work in every browser.

rich:toolTip not handling String values that contain quotes

I have ran into a particularly strange problem when implementing a RichFaces tool tip component. In my project I have a table that displays a list of Strings that are entered by the user, and I want there to be a pop-up of additional information when a user mouses over the strings in the list.
One of the requirements is that any string that is more than one word must contain double quotes "" when input by the user--e.g. a single word would be input as Java vs. a phrase "Java is cool".
So, I added a <rich:toolTip> to render additional info if it exists--and it works, except for strings that contain double-quotes. For example (as it's displayed in the table) "sample string" will not show additional information on mouseover.
My JSF code is simply:
<h:outputText id="keywordText" value="#{keywordData.keyword}"/>
<rich:toolTip for="keywordText" rendered="#{keywordData.comments != null}" value="#{keywordData.comments}"/>
Like I said, this works for words/strings that do not contain quotes. I am wondering if there is a workaround within JSF/RichFaces I can use in order to get this to work properly with a string that contains quotes. Or perhaps some assistance in writing a custom JavaScript function that forces or "tricks" RichFaces into handling quotation marks in a string correctly?
Thanks for any help in advance!
Edit: I am using RichFaces 3.3.3
In the page source, for the string "Testing Quotes" (does not work) I found this:
<span id="j_id138:j_id144:keywordTable:"Testing Quotes":keywordText">"Testing Quotes"</span>
<span id="j_id138:j_id144:keywordTable:"Testing Quotes":j_id159" class="rich-tool-tip " style="z-index:99; ">
<span id="j_id138:j_id144:keywordTable:"Testing Quotes":j_id159content">
<p>This comment should display</p>
</span>
<span id="j_id138:j_id144:keywordTable:"Testing Quotes":j_id159script" style="display:none">
<script id="scriptj_id138:j_id144:keywordTable:" quotes":j_id159"="" testing="" type="text/javascript">
new ToolTip("j_id138:j_id144:keywordTable:"Testing Quotes":j_id159","j_id138:j_id144:keywordTable:"Testing Quotes":keywordText",{'showEvent':'mouseover'} );
</script>
</span>
You can see that the quotations in the string itself (which appears to supposed to be part of the id attribute) are being misinterpreted in the new ToolTip parameters. And for a string testkeywordawesome without quotes you can see it works (because it does not contain quotes):
<span id="j_id138:j_id144:keywordTable:testkeywordawesome:keywordText">testkeywordawesome</span>
<span id="j_id138:j_id144:keywordTable:testkeywordawesome:j_id159" class="rich-tool-tip " style="z-index: 99; visibility: hidden; display: none; left: 63.7833px; top: 210.75px;">
<span id="j_id138:j_id144:keywordTable:testkeywordawesome:j_id159content">
<p>the best comment in the world</p>
</span>
<span id="j_id138:j_id144:keywordTable:testkeywordawesome:j_id159script" style="display:none">
<script id="scriptj_id138:j_id144:keywordTable:testkeywordawesome:j_id159" type="text/javascript">
new ToolTip("j_id138:j_id144:keywordTable:testkeywordawesome:j_id159","j_id138:j_id144:keywordTable:testkeywordawesome:keywordText",{'showEvent':'mouseover'} );
</script>
</span>
Edit2: The tool tips exists in a rich:column, of which exists in a rich:extendedDataTable. Below are their code:
<rich:extendedDataTable value="#{keywordEntry.globalKeywordsDataModel}"
rendered="#{fn:length(keywordEntry.globalKeywords) gt 0}"
styleClass="removeEDTSortIcon removeEDTContextMenu"
id="keywordTable" rowClasses="row1, row2"
var="keywordData" rows="0" noDataLabel=" "
headerClass="#{displayHeader == null or displayHeader ? 'rich-table-header' : 'hide'}"
rowKeyVar="keywordRowIdx" enableContextMenu="false"
sortMode="#{globalKeywordListSort.multiSortEnabled ? 'multi' : 'single'}"
sortPriority="#{globalKeywordListSort.sortOrderList}"
width="#{eStaffUser.userKeywordAdmin ? '750px' : '750px'}"
height="#{((fn:length(keywordEntry.globalKeywords)*30 + 50) lt 480) ? (fn:length(keywordEntry.globalKeywords)*30 + 50) : 480}px"
>
and
<rich:column id="#{globalKeywordSortFieldEnumBean.KEYWORD}" selfSorted="false" width="#{eStaffUser.userKeywordAdmin ? '48%' : '52%'}" sortBy="#{keywordData.keyword}"
sortOrder="#{globalKeywordListSort.dataTableColumnSortClass[globalKeywordSortFieldEnumBean.KEYWORD].sortOrder}">
id="j_id138:j_id144:keywordTable:"Testing Quotes":keywordText"
This means that one of the parents of <h:outputText id="keywordText"> has its id defined by something that evaluates to "Testing Quotes", that's obviously bad.
OK, so the root of the issue was that the rich:extendedDataTable uses an ID supplied by each entry to generate a unique ID for each table row. So the problem ended up being in the underlying "Model Managed-Bean" that implemented a generic data entity interface, this interface defines a getEntityId() method and in this case, the "ID" returned was the keyword value itself, since there was no true (i.e., database) entity ID such as a primary key:
public class KeywordDataBean implements SummaryDataEntityIF<String>
The problem was resolved by changing the interface's implementation to Integer and returning the hash as the unique ID for each keyword object:
public class KeywordDataBean implements SummaryDataEntityIF<Integer>
This forced the html id generated by the rich:extendedDataTable to be a simple integer number instead of a (keyword) string containing quotes, allowing the rich:toolTip to work properly.

JSF t:messages - How to avoid tables?

I got JSF Tomahawk messages and those messages got rendered as one HTML-Table. How do I avoid such tables? I would prefer one div for all messages which contains one paragraph for each message. Thanks in advance.
My JSF-file-snippet:
<t:messages layout="table" replaceIdWithLabel="true" showDetail="true" showSummary="false" styleClass="mycustomclasswhichgrabsthisshit" />
Check the Tomahawk tag documentation. The <t:messages> tag documentation says the following:
Name | Type | Supports EL? | Description
-------+--------+--------------+---------------------------------------------
layout | String | Yes | The layout: "table" or "list". Default: list
So, fix it accordingly:
<t:messages layout="list" ... />
Or just remove it altogether. It's the default already.
You can if necessary remove the list bullets using CSS:
.mycustomclasswhichgrabsthisshit {
list-style-type: none;
}
(disclaimer: the ranty classname is literally copied from your example, it's not mine)

How to insert tab in a jsf page? [duplicate]

This question already has an answer here:
h:outputText seems to trim whitespace, how do I preserve whitespace?
(1 answer)
Closed 7 years ago.
How do I insert a tab in a jsf page?
<h:outputText class="text" value="#{BackingBean.line1}" />
This doesn't work:
String line1 = "Scale \t: " + vss.getScale();
Any idea?
Whitespace is in HTML by default not accounted as part of presentation. You'd need to use HTML elements like <br/> for a newline or <ul><li> for lists or <dl><dt><dd> for definitions. Most likely the <dl><dt><dd> is most suitable for you.
If you have a hard head in, you could always just set the CSS white-space property of the parent element to pre.
E.g.
<h:outputText ... styleClass="preformatted" />
(please note that the class attribtue is invalid. It should be styleClass)
with
.preformatted {
white-space: pre;
}

Custom download servlet

I looked into BalusC's code for a custom download servlet from absolute path (see http://balusc.blogspot.com/2007/07/fileservlet.html#FileServletServingFromAbsolutePath). I'm not a Java Web Developer Expert so I would love if someone can explainme this part of the code
private String filePath;
// Actions ------------------------------------------------------------------------------------
public void init() throws ServletException {
// Define base path somehow. You can define it as init-param of the servlet.
this.filePath = "/files";
// In a Windows environment with the Applicationserver running on the
// c: volume, the above path is exactly the same as "c:\files".
// In UNIX, it is just straightforward "/files".
}
When does the init method gets called? Why do we need the filePath to be set in the init method?
I have an XHTML (Mojarra+IceFaces) with something like the code below that works great. My page is missing just the part of downloading the file which is referenced by the outputLink tag
<ice:tree id="tree"
value="#{treeBean.model}"
var="item"
hideRootNode="false"
hideNavigation="false"
>
<ice:treeNode>
<f:facet name="icon">
<ice:panelGroup style="display: inline">
<h:graphicImage value="#{item.userObject.icon}" />
</ice:panelGroup>
</f:facet>
<f:facet name="content">
<ice:panelGroup style="display: inline-block">
<ice:outputLink value="#{item.userObject.filePath}">
<ice:outputText value="#{item.userObject.fileName}"/>
</ice:outputLink>
</ice:panelGroup>
</f:facet>
</ice:treeNode>
</ice:tree>
In my Backing bean I have two fields fileName (just the name of the filewith extension e.g. Image.jpeg) and filepath (the ABSOLUTE path of the file in the server). Finally I want to download the file with the custom servelet, how can I do that??
Cheers,
UPDATE
Let's say mi base-dir is /SRC and under that dir I have all my xhtml pages and the WEB-INF and META-INF and aditionally I have a dir called dataFiles under dataFiles I have the following structure
--dataFiles
|----Enterprise1
| |--User1
| | |--goodFiles
| | | |--ok.txt
| | |--badFiles
| | |--bad.txt
| |--User2
| | |--goodFiles
| | | |--ok.txt
| | |--badFiles
| | |--bad.txt
|----Enterprise2
|--User1
| |--goodFiles
| | |--ok.txt
| |--badFiles
| |--bad.txt
|--User2
|--goodFiles
| |--ok.txt
|--badFiles
|--bad.txt
that's how I render the tree with IceFaces and I just have the filename in the backing bean (i.e. ok.txt or bad.txt) but I cannot figure out how to download the file pointing by the link in the tree.
Well finally got it work.
First of all thanks to BalusC, there were some posts here that helped me understand but someone delete them. Anyway, here's what I've learned.
In Servlet's init method the filePath variable must point to the absolute path where the files to download are.
In the web.xml the servlet-map-url-pattern will cause to execute the servlet when the browser has that url pattern.
In the xhtml page tha value of the link should begin with the url-pattern followed by the name (or a path+FileName) so when you click the link the download begins.
That's all I had to do !
In the example of the question, the filePath variable in the servlet's init method will point to the absolute path, something like C:\myApp\dataFiles
Then in the xhtml will call the servlet with something like
<ice:outputLink value="dl/myPath/#{myBean.fileName}>
<ice:outputText value="#{myBean.fileName}"/>
</ice:outputLink>
Note 1: that the first part of the value of the outputLink is dl/ this is because the url-pattern for the servlet to download is mapped to it
Note 2: in the outputLink the value of myPath could be dl/Enterprise1/User1/file1.ext
Cheers

Resources