0

I am making an JSF 2 application. Sometimes I want to do simple things that are easy to do using plain HTML but I get error messages that I don't understand.

For example I sometimes want to write:

<a href="urly/pagey?test1=ee&test2=oo">Test</a>

But this makes the page break because of "?test1=ee&test2=oo". Having only one parameter seems to be fine but if I try to add more parameters using "&" it complains and says I need to use a ';'-delimiter.

Any explanations why this happens and maybe how to get around it?

numfar
  • 1,637
  • 4
  • 18
  • 39
  • AFAIK the `href` attribute of an anchor HTML tag takes a complete url so you would need to specify it with its suffix: `href="urly/pagey.xhtml?test1=ee&test2=oo"`. Anyway, if using JSF why don't you just use `h:link outcome="urly/pagey"` and use `f:param` tags instead? I think it makes it to be cleaner. – Aritz Jan 21 '14 at 09:47
  • I don't need to specify it if I for example have a servlet check the userpath and send a forward to the "pagey.xhtml". And the problem is the parameters. I might be able to do it using the facelet tags you mentioned, but I'm new to facelets and it will take me a while to check if they will do exactly what I wan't them to do. Which I know how to do very quickly using plain html. And since I need to work fast and I have no perticular use of of using facelets in this instance I didn't feel it was neccessary. And also I'm just curious why it didn't work. – numfar Jan 21 '14 at 10:07
  • An `h:link` with both `f:param` tags generates exactly what you're expecting. See [this](http://stackoverflow.com/a/20882154/1199132). For your case would be as ``. Also I've noticed your problem could be about encoding. Try scaping the & character: http://stackoverflow.com/a/8123031/1199132 – Aritz Jan 21 '14 at 10:09
  • Almost, but not quite. I want to produce: Test. But all I can do is: Test – numfar Jan 21 '14 at 10:27
  • What exactly `urly/pagey` is? Is it a facelet view? If not, it can't be accesed by an outcome. Just use [`h:outputLink`](http://www.jsftoolbox.com/documentation/help/12-TagReference/html/h_outputLink.html) instead. – Aritz Jan 21 '14 at 10:37
  • By now, the problem as described in the comments is completely different from the problem in the question. To answer the question, you need `&` instead of `&`. But I'm not sure what the issue is with the `.xhtml` suffix. – Mr Lister Jan 23 '14 at 08:01
  • Ah, yes. Thank you. :) But why is it like that? Before (writing only JSP-files, not using JSF) I could write `&` without a problem. About the suffix, I use a servlet to match the url and then the parameters to decide which page to forward to. It's not really a problem though. – numfar Jan 23 '14 at 09:04
  • You should always use `&` when you mean an ampersand. `&` is plain wrong! Now XML doesn't have any error recovery, so you'll need to follow the rules very strictly in an XML environment. In HTML on the other hand, the system can figure out that you do mean an ampersand, and you won't get an error. There is a danger that you may use an entity name by mistake though. For example, `?cow=7&bull=8` can go horribly wrong! – Mr Lister Jan 23 '14 at 10:13
  • Okay, I get it now. But doesn't this destroy/limit the use of EL in attributes? Or atleast make it really messy to write? For example I'm used to doing stuff like: `${(1==0 && 0==0)?('Truey'):('Falsey')}` inside attributes. – numfar Jan 23 '14 at 11:51
  • Unless it contains `&` or `<` or `"`, there's no need to expand anything into references if that's what you mean. – Mr Lister Jan 23 '14 at 14:41

0 Answers0