Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can we render a jsf element with a # inside #

 
M. Phaneendra Vijay
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a bean called 'budget' and a property in it called 'ddoVariablesValues', which is a HashMap.

In xhtml, I render a table with the HashMap values.

Each cell in the table is an <input type="text"> i.e.,




"#{ddoVar.ddoCode}_#{colVar.columnId}_#{colVar.columnName}" is key in the ddoVariableValues --- for value attribute.

The value is not rendered because of # symbols inside # in the value attribute.

Please help me.
 
Tim Holloway
Saloon Keeper
Posts: 18363
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The octothorpe (#) isn't a very good choice as a delimiter, as you've seen. I've also discovered to my sorrow that it can cause grief when it appears in a URL (since it's the signal for the beginning of an anchor name).

You should check the documentation on EL, but the escape is probably either "\#" or "##".
 
M. Phaneendra Vijay
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No No. The problem is that #{ddoVar.ddoCode}_#{colVar.columnId}_#{colVar.columnName} is an EL element which has to be rendered to get the key value.



Suppose the value of #{ddoVar.ddoCode} is 1 and the value of #{colVar.columnId} is 800 and the value of #{colVar.columnName} is 'expenditure',

the value attribute in the <input type="text"> element should render as #{budget.ddoVariableValues["1_800_expenditure"]} which inturn should return appropriate value from the 'ddoVariableValues' HashMap based on the key '1_800_expenditure'.

I think you got me. I will explain in detail from the reverse

The appropriate HTML code rendered should be:



In the above code the value,

13 should be rendered from #{budget.ddoVariableValues["1_800_expenditure"]}

and '1_800_expenditure' should be rendered from #{ddoVar.ddoCode}_#{colVar.columnId}_#{colVar.columnName}

Thanks in advance.
Phani.
 
Tim Holloway
Saloon Keeper
Posts: 18363
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. First, it's kind of pointless to use an HTML <input> on JSF. You're discarding most of the benefits of JSF and I frankly can't see that you gain anything at all. A JSF inputText would be more appropriate.

The JSF equivalent would be more like this:


Except that in actual fact, it looks like you're iterating, so an even more appropriate thing would be to embed the inputText into a dataTable or dataGrid, resulting in:


I'm sure I have this a little garbled, since there are some rather unusual aspects to the problem as originally presented, but this is an effective solution to problems of this general nature. A more "real-world" version would add subheadings to the display for the ddoCodes and column names and probably further nest the input text inside a datagrid to get a column-wise display of the column values (which would further simplify the inputText value EL).
 
M. Phaneendra Vijay
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

Please see the below code:



The above code generates an excel sheet type UI.

The table should be scrollableDataTable. It should have 4 individual columns (SI.No, DDO, DTO, DDO Code). And the remaining columns should be populated from 'variableNames' list. And each cell in the UI should be unique. So I have taken the name as a combination of ddoCode, columnId and columnName combined to form a unique key. Then the value for each cell (given by the user) is taken as a value in the HashMap (ddoVariableValues) and the key for it is the combination of ddoCode, columnId and columnName.

The name of the input text is also the combination of ddoCode, columnId and columnName in the JSF. So I get the value for the input text element from the HashMap based on the ddoCode, columnId and columnName.

In this way, the cells get populated with the data from the HashMap.

I have also tried <h:inputText id="#{ddoVar.ddoCode}_#{colVar.columnId}_#{colVar.columnName}" />, but the scrollableDataTable did not show the columns populated from the list 'variableNames'
 
Tim Holloway
Saloon Keeper
Posts: 18363
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Last time I did something like that, I used an applet and HTTP tunnelling. Partly because that was before AJAX, but also because it's fairly simple and unless you get really creative with CSS, using HTTP input controls take up a lot more screen real estate.

Excel's model is a 2-dimensional array, and I really recommend that over trying to cram everything into a hashmap. It's a lot easier to work with.

In practical terms, however, I'm not sure that I'd even use JSF for something like this. If I wanted to avoid the nuisances of applets, there are some good AJAX-based solutions available. I think the Google Web Toolkit may have a spreadsheet component, as a matter of fact.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic