1

In my JSF 2.1 project, I have a custom facelet tag file that defines an actionListener using the solution provided in Passing backing bean action to Facelet tag file .

The problem is, I'd like to have the option of not having the actionListener when using the tag, and that solution makes the action attribute required. I'd rather not have to create two versions of the tag (with and without actionListener) just for this, because the code is relatively large, and that would impose some maintenance trouble.

What should I do to conditionally add the actionListener in the tag implementation, without Java coding (if that is even possible)?

Community
  • 1
  • 1

1 Answers1

0

You cant use EL conditional expressions into action attribute, for more info you can look at this question

I dont know when you want (on wich event) to execute the actionListener method but you can change the actionListener for an a4j:support tag and try the following code

You can call a js function for the condition logic or just save the condition into a parameter (depending on logic complexity)

<ui:param name="parameter" value="#{bean.parameterValue}/>
<h:inputText>
         <a4j:support event="onchange" onsubmit="if(checkCondition(parameter))){return true;}" actionListener="#{bean.yourMethod()}"/>
</h:inputText>

function checkCondition(parameter){
   //your logic
}

Hope it helps

Marcos Martínez
  • 545
  • 2
  • 9
  • 24