0

Trying to develop a composite component using jsf2.0 (Mojarra) which should render command buttons dynamically based on the list from the bean. I was able to render the buttons but action is not getting triggered.Could any one please help me to resolve the issue?

Here follows the code

<composite:interface>
<composite:attribute name="buttonList" required="true"
type="java.util.List" />
<composite:attribute name="beanName" required="true"
    type="java.lang.Object" />
</composite:interface>
<composite:implementation>

<ui:repeat var="listItem" value="#{cc.attrs.buttonList}">
<h:commandButton value="#{listItem.buttonName}"
action="#{cc.attrs.beanName.listItem.buttonAction}">
</h:commandButton>
</ui:repeat>
</composite:implementation>

This is used as

<utils:buttonGroup buttonList="#{testButtonBean.buttonList}"
beanName="#{testButtonBean}" />

The bean looks like

public class TestButtonBean {

public List<ButtonPOJO> buttonList = new ArrayList<ButtonPOJO>();
public List<ButtonPOJO> getButtonList() {
  return buttonList;
}   

public void setButtonList(List<ButtonPOJO> buttonList) {
this.buttonList = buttonList;
}

public void preProcess() {
if (null != buttonList && buttonList.size() == 0) {
ButtonPOJO ob1 = new ButtonPOJO("Continue", "next");
ButtonPOJO ob2 = new ButtonPOJO("Back", "prev");
buttonList.add(ob1);
buttonList.add(ob2);
}

}

public String next() {
return "page1";
}

public String prev() {
return "page2";
}
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sathya Elangovan
  • 163
  • 3
  • 14

1 Answers1

0
action="#{cc.attrs.beanName.listItem.buttonAction}"

This is not right. This syntax is basically looking for a property listItem on beanName and then trying to invoke the literal action buttonAction() on it.

You need the brace notation action="#{bean[methodName]}" if you want to specify the action method name as string coming from another bean property.

action="#{cc.attrs.beanName[listItem.buttonAction]}"

Unrelated to the concrete problem, if the above solution still fails, then that can only mean that the value="#{cc.attrs.buttonList}" has incompatibly changed during the form submit request. You need to make sure that exactly the same list is prepared during the postback as it was during the initial request. See also point 4 of commandButton/commandLink/ajax action/listener method not invoked or input value not updated.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Many thanks for your quick response.Action is not triggering after adding brace notation like below action="#{cc.attrs.beanName[listItem.buttonAction]} Aldo My Bean is in view scope and buttonList is constructed during postconstruct.please advise. – Sathya Elangovan Dec 06 '12 at 17:07
  • I have done a mistake in my action.Its working fine as you suggested.Moreover is this a right way in creating composite component? Please advice. – Sathya Elangovan Dec 17 '12 at 18:06