wood burning stoves 2.0
The moose likes JSF and the fly likes how to set the length of a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "how to set the length of a string" Watch "how to set the length of a string" New topic

how to set the length of a string

Dura Hurtado
Ranch Hand

Joined: Feb 16, 2011
Posts: 120
Hi, I am trying to set the length of a string when it is shown inside a panel this way:

<p:panel header="m">
<div id='content'>
<p> <hutputText value="#{Content.load}" styleClass="element"/></p>

then in the .css file (styleClass="element") I´ve set the width value, this is a bizarre way of course it doesn´t works, my .css is:

.element{width: 20px;}

¿Any idea?


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17039

Like I mentioned in another answer, HTML isn't a strict character-based definition language. Not only does it ignore newlines, it will remove multiple spaces when it displays a page.

A popular way of getting around this is to fake it using the "non-break space" entity ("&nbsp;"), but that's brute force.

On the other hand, you can't set width on an outputText JSF tag, because the outputText generates an HTML <span>, which doesn't support width. So what you have to do is embed the outputText in a construct that does support widths, such as a column in a table. Or, in the case that you used, a panelGrid will do:

Note that I got rid of the raw HTML tags. They're not good practice and they weren't needed anyway. I also changed the capitalization on your bean name, since as a instance variable, it should begin with an uppercase letter. That should only be done for class names.

An IDE is no substitute for an Intelligent Developer.
Have you checked out Aspose?
subject: how to set the length of a string
It's not a secret anymore!