JSF Team URL Parameters

I would like to make a button that navigates to a different URL and passes some request parameters through the URL. OutputLink works, but I need a button, commandButton looks good, but I can pass parameters.

Is there a solution?

+7
jsf
source share
2 answers

h:commandButton does not start a GET request, but a POST request, so you cannot use it. If you are already using JSF 2.0 and the landing page is in the same context, you can use h:button to do this:

 <h:button value="press here" outcome="otherViewId"> <f:param name="param1" value="value1" /> <f:param name="param2" value="value2" /> </h:button> 

(here h:form is required here, as in h:outputLink ). This will create a button that will be otherViewId.jsf?param1=value1¶m2=value2 .

But if you're not already on JSF 2.0, it's best to just grab the CSS to create the link as a button.

 <h:outputLink styleClass="button"> 

with something like

 a.button { display: inline-block; background: lightgray; border: 2px outset lightgray; cursor: default; } a.button:active { border-style: inset; } 
+16
source share

Using the button, you bind the action , which is a method in the bean database, you can set the parameters in the backup bean and read them when you click the button from the method associated with the action . The action method should return a String that will be read by the navigation handler to check whether it needs to go to a new page according to the configuration in faces-config.xml .

 <h:form> <h:commandButton value="Press here" action="#{myBean.action}"> <f:setPropertyActionListener target="#{myBean.propertyName1}" value="propertyValue1" /> <f:setPropertyActionListener target="#{myBean.propertyName2}" value="propertyValue2" /> </h:commandButton> </h:form> 

Bean support:

 package mypackage; public class MyBean { // Init -------------------------------------------------------------------------------------- private String propertyName1; private String propertyName2; // Actions ----------------------------------------------------------------------------------- public void action() { System.out.println("propertyName1: " + propertyName1); System.out.println("propertyName2: " + propertyName2); } // Setters ----------------------------------------------------------------------------------- public void setPropertyName1(String propertyName1) { this.propertyName1 = propertyName1; } public void setPropertyName2(String propertyName2) { this.propertyName2 = propertyName2; } } 

This example is taken from here (BalusC blog, maybe it will come and tell you to check this link, but I'm faster !: p)

Of course, to achieve this, the bean must be set as session scoped . If you want it to be request scoped , you can follow the steps here

+5
source share

All Articles