views:

514

answers:

2

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"&gt;
    <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"&gt;

but this does not:

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

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;amp;secondParam=otherValue"&gt;

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

alt text

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"&gt;
<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"&gt;
    <h:head />
    <h:body>
        <h:form>
            <p:linkButton value="Click me" href="http://stackoverflow.com" />
        </h:form>
    </h:body>
</html>

Primefaces 2.1 release.

+1  A: 

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"&gt;
    <h:head>
        <title>Test</title>
    </h:head>
    <h:body>
        <p:linkButton value="test" href="http://stackoverflow.com" />
    </h:body>
</html>
BalusC
I did try p:linkButton, but it doesn't work. Firebug says the GET request is aborted, and the current page is POSTed again.
Gabor Kulcsar
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...
Gabor Kulcsar
Gabor Kulcsar
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?
Gabor Kulcsar
Gabor Kulcsar
BalusC
As to your screenshot, you're viewing it in `All` tab. What kind of request is the GET request? `HTML` (normal) or `XHR` (ajax)?
BalusC
+1  A: 

Hi,

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

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

Cagatay Civici
Ah, nice. Can you explain the particular problem in detail anyway?
BalusC
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 ;-)
Gabor Kulcsar
Here is new p:button;http://www.primefaces.org:8080/prime-showcase-labs/ui/button.jsf
Cagatay Civici