f:param not working when used with trinidad 2

355 views Asked by At

I am using JSF 2 Trinidad 2(MyFaces) and trying to use f:param in a command button

<tr:commandButton text="Submit" action={backingBean.actionSubmit}>
<f:param name="isSubmit" value="Yes" />
</tr:commandButton>

Basically I am trying to pass the param value for submit button and only perform the validation if a Submit button is clicked adding the condition to the required attribute for input elements to check for the submit button.

Is there a way to identify a particular button click in JSF2/Trinidad2 so that I can check for that button click in the validation method.

2

There are 2 answers

0
lkdg On

I am using JSF 1.2 but I think it works in JSF 2.0 the same way.

For your commandButton use an actionListener instead of action.

<tr:commandButton text="Submit" actionListener={backingBean.actionSubmit}> 

Within your bean you can get the id of your button:

public void actionSubmit(ActionEvent event)
{
   event.getComponent().getId();
}
0
Jasper de Vries On

You could consider to use <tr:setActionListener/>. In your case you could use something like:

<tr:commandButton text="Submit" action="#{backingBean.actionSubmit}">
  <tr:setActionListener from="submit" to="#{backingBean.pressedButton}" />
</tr:commandButton>

Basically you use it to copy an object from the from attribute to the to attribute. Note that you could use EL in the from attribute as well (#{someBean.someObject}).

In you backing bean you need to add a String member called pressedButton (with getter and setter). Now you can use the following code in your actionSubmit

if ("submit".equals(pressedButton))
{
  System.out.println("You pressed 'sumbit'");
}