5

I have this working code in my webapp:

<h:button value="Edit user..." outcome="/public/user" > <f:param name="userName" value="#{authBean.authUser}"/> </h:button> 

What it does:

  1. It makes the button send a GET
  2. It passes the specified parameter in the URL, making it bookmarkable.

What I need:

  • It should work like h:button above (send GET)
  • the button should look like other Primefaces buttons (eg. decorated with an image... etc).

This is the closest I could get:

<p:commandButton value="Edit user..." action="/public/user?faces-redirect=true" ajax="false" immediate="true" > <f:param name="userName" value="#{authBean.authUser}"/> </p:commandButton> 

It sends a POST that gets redirected to the new URL with a GET. However the parameter is lost in the process.

Another idea:

<p:linkButton value="Edit user..." href="http://localhost:8080/contextpath/faces/public/user.xhtml"> <f:param name="userName" value="#{authBean.authUser}"/> </p:linkButton> 

The GET request is aborted (??? according to Firebug) and the current page is POSTed again.

What is the proper way of doing this?

UPDATE: this works (on an empty page, with no p:dataTable):

<p:linkButton value="Edit user..." href="http://localhost:8080/contextpath/faces/public/user.xhtml?userName=myusername"> 

but this does not:

<p:linkButton value="Edit user..." href="http://localhost:8080/contextpath/faces/public/user.xhtml?userName=myusername&secondParam=otherValue"> 

the latter results in:

500: javax.servlet.ServletException: Error Parsing /sample0.xhtml: Error Traced[line: 14] The reference to entity "secondParam" must end with the ';' delimiter.


UPDATE2: the & should be escaped:

<p:linkButton value="Edit user..." href="http://localhost:8080/contextpath/faces/public/user.xhtml?userName=myusername&amp;secondParam=otherValue"> 

and it looks good... but I still get the GET aborted and POST resent:

alt text http://img64.imageshack.us/img64/1017/primefaceslinkbutton.jpg

This is the full empty page I've been trying it with:

<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.prime.com.tr/ui"> <h:head /> <h:body> <h:form> <p:linkButton value="Click me" href="http://stackoverflow.com" /> </h:form> </h:body> </html> 

Primefaces 2.1 release.

2 Answers 2

3

In PrimeFaces 2.2., we'll deprecate linkButton and introduce p:button. Issue ticket;

http://code.google.com/p/primefaces/issues/detail?id=1037

Sign up to request clarification or add additional context in comments.

3 Comments

Ah, nice. Can you explain the particular problem in detail anyway?
OK, so I will stick to h:button without images for now. Thank you BalusC for your time and effort, and of course Cagatay for the answer ;-)
1

Use p:linkButton.


Update: as per your update with the code example, the URL should be specified in href attribute, not in the url attribtue. Also see the component's documentation which I linked here above.

The symptoms at least sounds like as if you're firing an asynchronous (Ajax) GET request, not a synchronous one. FireBug would then indeed give this kind of error when the request is fired on a different domain.

Don't you have some other Javascripts which are disturbing/colliding with the linkButton's default behaviour? The button is navigating by a simple onclick="window.location=newurl;".


Update 2: does it work if you test it standalone in a simple page? E.g.

<!DOCTYPE html> <html xmlns="http://www.w3c.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.prime.com.tr/ui"> <h:head> <title>Test</title> </h:head> <h:body> <p:linkButton value="test" href="http://stackoverflow.com" /> </h:body> </html> 

7 Comments

I did try p:linkButton, but it doesn't work. Firebug says the GET request is aborted, and the current page is POSTed again.
Sorry, I didn't do a full copy/paste. I am using the "href" attribute, "url" isn't even accepted by Netbeans. I will now check for other javascript...
On an empty page p:linkButton works... sort of. f:param doesn't work. If I specify the parameter in the URL directly (eg: ".../user.xhtml?userName=myusername") it works. When I specify one more parameter, Glassfish says 500: javax.servlet.ServletException: Error Parsing /sample0.xhtml: Error Traced[line: 14] The reference to entity "relVerMin" must end with the ';' delimiter. (relVerMin was my second parameter, such as: ".../delrel.xhtml?relVerMaj=1&relVerMin=0")
Woohoo! I use p:dataTable on the original page. I inserted the same table on the empty page, and the problem appeared... no custom javascript... so p:dataTable is not compatible with p:linkButton?
OK, I think I am getting tired. Maybe I should escape the "&"! Will try out tomorrow.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.