Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Check <a href="http://balusc.blogspot.com/2006/06/communication-in-jsf.html" rel="nofollow noreferrer">this</a> out. I have the same problems as you, but i solved it after reading <a href="https://stackoverflow.com/users/157882/balusc">BalusC</a>'s link.</p> <p>For short, there's what u're talking abt:</p> <p><strong><em>f:attribute:</strong> with the <strong>h:commandLink</strong> and <strong>h:commandButton</strong> tags you can also trigger a method of the backing bean using the <strong>actionListener</strong> attribute. With this you can also use the f:attribute tag to dynamically pass the parameters. Here is an example:</em></p> <pre><code>&lt;h:form&gt; &lt;h:commandLink value="Click here" actionListener="#{myBean.action}"&gt; &lt;f:attribute name="attributeName1" value="attributeValue1" /&gt; &lt;f:attribute name="attributeName2" value="attributeValue2" /&gt; &lt;/h:commandLink&gt; &lt;h:commandButton value="Press here" actionListener="#{myBean.action}"&gt; &lt;f:attribute name="attributeName1" value="attributeValue1" /&gt; &lt;f:attribute name="attributeName2" value="attributeValue2" /&gt; &lt;/h:commandButton&gt; &lt;/h:form&gt; </code></pre> <p><em>Those attributes can be retrieved using <strong>getAttributes</strong>() of the parent UI component, which on its turn can be retrieved by the <strong>ActionEvent</strong> passed by the <strong>actionListener</strong>.</em></p> <pre><code>package mypackage; import javax.faces.event.ActionEvent; import net.balusc.util.FacesUtil; public class MyBean { // Actions ----------------------------------------------------------------------------------- public void action(ActionEvent event) { String attributeName1 = FacesUtil.getActionAttribute(event, "attributeName1"); String attributeName2 = FacesUtil.getActionAttribute(event, "attributeName2"); System.out.println("attributeName1: " + attributeName1); System.out.println("attributeName1: " + attributeName1); } } package net.balusc.util; import javax.faces.event.ActionEvent; public class FacesUtil { // Getters ----------------------------------------------------------------------------------- public static String getActionAttribute(ActionEvent event, String name) { return (String) event.getComponent().getAttributes().get(name); } } </code></pre> <p><em>The variables <strong>attributeName1</strong> and <strong>attributeName2</strong> now should contain the values attributeValue1 and <strong>attributeValue2</strong> respectively.</em></p> <p><em>Take care that each attribute name should be unique and should not overwrite any default component attributes, like "id", "name", "value", "binding", "rendered", etc.</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload