...">

Creating p: commandButton works like h: button

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 does he do:

  • It makes the button send get
  • It passes the specified URL to the URL, making it bookmarkable.

What I need:

  • It should work like h: button above (send GET)
  • the button should look like other Right buttons (for example, 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 which is redirected to the new URL using 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 sent again.

What is the right way to do this?

UPDATE: this works (on a blank page without p: dataTable):

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

but this is not so:

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

the latter leads to:

500: javax.servlet.ServletException: /sample 0.xhtml: [: 14] "secondParam" ';' .


UPDATE2: :

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

... GET POST resent:

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

, :

<?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>

2.1.

+5
2

PrimeFaces 2.2. linkButton p: button. ;

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

+3

p:linkButton.


: , URL- href, url. . , .

, , , (Ajax) GET, . FireBug ​​, .

Javascripts, / linkButton ? onclick="window.location=newurl;".


2: , ? .

<!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>
+1

All Articles