Addicted
Addicted

Reputation: 1704

commandlink, outputlink , commanbutton, rich:menuItem to use

I have faced one difficulty in JSF 2 based application.
I wanted to use navigation from one view to another along with a value passing through rich:menuItem,

  1. So I tried to use h:outputLink and it navigates as well, but is not passing the value which i want to pass before it navigates to display the required resultset.
  2. The same for a4j:commandLink.
  3. then I used a4J:commandButton itself to perform this by using action and actionListener. Here Action will navigate to next view and Listener will pass the value to the required class and "listener will be called before action". The code for doing this is....

    <rich:menuItem ajaxSingle="true">
         <a4j:commandButton value="Show Particulars" action="details" event="onclick" actionListener="#{payeeParticularsController.showParticulars}"/>
    </rich:menuItem>        
    

but this button looks really awkward for use.
So can anybody help me to do this by either using outputLink, commandLink, rich:menuItem (would be best to do), or any other well user friendly way.

Upvotes: 1

Views: 2222

Answers (2)

alkimisticus
alkimisticus

Reputation: 61

Try this. It's working for me.

<rich:menuItem submitMode="none">
   <h:commandLink value="Show Particulars" action="details" actionListener="#{payeeParticularsController.showParticulars}"/>
</rich:menuItem>

or if you have ajax

<rich:menuItem submitMode="none">
   <a4j:commandLink value="Show Particulars" reRender="body" action="details" actionListener="#{payeeParticularsController.showParticulars}"/>
</rich:menuItem>

And, I would sugges to use attribute immediate="true" in menues.

Reference : http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_menuItem.html

Upvotes: 1

Mango
Mango

Reputation: 660

Try it this way, if it helps

<h:commandLink id="btn" value="Show Particulars" action="{payeeParticularsController.showParticulars}">
     <f:param name="menuItem" value="#{}" />
 </h:commandLink>

Where the command link takes the menu item as a parameter

UPDATE: In the bean

public String showParticulars(){
   // get the f:parama value using facesContect
   // use it as required
   ...
   return "\newView.xhtml";
}

UPDATE 2:

If the above did not work try it this way

 <rich:menuItem submitMode="ajax" value="Show Particulars" action="#{Bean.showParticulars}" >
 </rich:menuItem>

and the Bean would be

public String showParticulars() 
{
      ..
return "/logout.xhtml";
}

where the submitMode="ajax" will help u make it work as commandLink and the Bean's show particulars() will navigate to another view

Upvotes: 2

Related Questions