Page 1 of 2
DataTable - CommandButton doesn't work even inside p:column
Posted: 27 Dec 2010, 01:06
by Daedin
Hello,
I have a commandButton inside a DataTable. However the "action" isn't called when I click on it (same effect with an actionListener); I added logs at the beginning of the server action, and it never shows.
Please note that the button works fine when outside from the datalist.
Here is my code:
Code: Select all
<h:form id="compSearchForm">
<p:dataTable var="competency"
value="#{competencySearchBean.matchingCompetencies.toArray()}">
<p:column>
<f:facet name="header">
<h:outputLabel value="Title" />
</f:facet>
<h:outputText value="#{competency.title}" />
</p:column>
<p:column>
<p:commandButton value="Go" id="actionButton"
action="#{myBean.doAction}" />
</p:column>
</p:dataTable>
</h:form>
Would you have any idea as to what the issue might be?
Re: DataTable - CommandButton doesn't work even inside p:col
Posted: 27 Dec 2010, 11:02
by Daedin
Just thought it could be linked to the fact that I specified an "id", thus producing several components with the same id. Just removed the ID tag, but it didn't solve the issue.
Re: DataTable - CommandButton doesn't work even inside p:col
Posted: 27 Dec 2010, 13:25
by lordpixel
Can you post the actionListener?
Re: DataTable - CommandButton doesn't work even inside p:col
Posted: 27 Dec 2010, 13:53
by healeyb
Are you using f:viewParam on the page?
Re: DataTable - CommandButton doesn't work even inside p:col
Posted: 27 Dec 2010, 14:28
by Daedin
The action is very simple:
Code: Select all
public String doAction() {
System.out.println("In action");
return null;
}
I have also tried to turn it in an actionListener
Code: Select all
public String doAction(ActionEvent event) {
System.out.println("In actionListener");
return null;
}
And I am not using any f:viewParam. I have tried to tinker a bit with the f:setPropertyActionListener though.
Re: DataTable - CommandButton doesn't work even inside p:col
Posted: 27 Dec 2010, 21:44
by westfarmer
is there another cascade form?
Re: DataTable - CommandButton doesn't work even inside p:col
Posted: 27 Dec 2010, 22:56
by Daedin
No, this is the top form. I double-checked in the source code, and my button has an (automatically generated) id in the form: form_id:datalist_id:row_number:button_id
Re: DataTable - CommandButton doesn't work even inside p:col
Posted: 28 Dec 2010, 02:19
by healeyb
This line worries me a little. It sort of looks ok on detail however I would
just return a Collection<t> and have the var= pointing to a T.
value="#{competencySearchBean.matchingCompetencies.toArray()}">
Then refer to #{competency.name} or whatever.
If that doesn't help I'm going to load it into Glassfish and see what
happens, because it looks ok to me.
Is this an academic project?
Regards,
Brendan.
Re: DataTable - CommandButton doesn't work even inside p:col
Posted: 28 Dec 2010, 11:04
by Daedin
In fact the "matchingCompetencies" is a java.util.Set instance, and can't be iterated through, which is why I use the toArray(). I'll try and change this to have the backing bean return a collection that can be iterated through by the datalist.
This isn't an academic project, but a personal one
Anyway, thanks a lot for your support. It's very kind of you.
EDIT: changed it a little bit to have the Backing Bean return a List<T> instead of a Set<T>, but the behaviour stays the same.
Re: DataTable - CommandButton doesn't work even inside p:col
Posted: 28 Dec 2010, 13:11
by Daedin
Don't know if this can help, but this is the generated HTML for the button:
Code: Select all
<button type="submit"
onclick="PrimeFaces.ajax.AjaxRequest('/levelup/pages/protected/character.jsf',{formId:'compSearchForm',async:false,global:true,source:'compSearchForm:compSearchTable:0:compBuyButton',process:'@all'});return false;"
name="compSearchForm:compSearchTable:0:compBuyButton"
id="compSearchForm:compSearchTable:0:compBuyButton"
class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
role="button" aria-disabled="false"><span
class="ui-button-text">Buy</span></button>
EDIT: and here is the HTML of the same button, but taken out of the datatable (which actually performs the action when I click on it):
Code: Select all
<button type="submit"
onclick="PrimeFaces.ajax.AjaxRequest('/levelup/pages/protected/character.jsf',{formId:'compSearchForm',async:false,global:true,source:'compSearchForm:compBuyButton',process:'@all'});return false;"
name="compSearchForm:compBuyButton" id="compSearchForm:compBuyButton"
class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
role="button" aria-disabled="false"><span
class="ui-button-text">Buy</span></button>
The only difference between the two of them is the ID. I'll try and play with the "prependId" attribute a bit.