-
1. Re: a4j:commandLink action not working in rich:datatable[richfaces 4.2.2]
healeyb Jun 16, 2012 5:26 AM (in response to sabarinathsss)Hi, it's probably best in these situations to post the code that isn't working so that everyone can take a look and try
to figure out what's wrong. Having said that I have to admit to having all sorts of problems posting xhtml on this board!
Using a4j:commandLink/Button inside a datatable does work so you must be doing something wrong. Request
scope really doesn't work properly with ajax so the first thing to try is @ViewScoped. Other things that can cause
this behavior are that you have validation problems, i.e. an input component with required="true", and you need to
add an h:messages (or equivalent) to track this down.
There is a truly excellent check list for tracking down this sort of problem here (BalusC's answer of course):
Regards,
Brendan.
-
2. Re: a4j:commandLink action not working in rich:datatable[richfaces 4.2.2]
sabarinathsss Jun 16, 2012 8:37 AM (in response to healeyb)Here is my code
<h:form onsubmit="return false;">
<table style="width: 100%;" border="0">
<tbody>
<tr>
<td>
<a4j:commandButton value="Populate Dependents Table" action="#{DependentManagedBean.getDependentslist()}" render="DependentDataTable">
<a4j:param value="0" assignTo="#{DependentManagedBean.mDmsCertRequestId}"></a4j:param>
</a4j:commandButton>
</td>
</tr>
<tr>
<td>
<rich:dataTable id="DependentDataTable" styleClass="smallgrid" style="width:100%;" value="#{DependentManagedBean.dmsCertRequestDependentsList.dmsCertRequestDependentsList}" var="dependent" >
<f:facet name="header">
<h:outputText value="Your List of Dependents" styleClass="BlueHeader"/>
</f:facet>
<rich:column>
<f:facet name="header" >
<h:outputText value="Name" styleClass="header" style="width:90px;"/>
</f:facet>
<h:outputText value="#{dependent.firstName} #{dependent.middleInitial} #{dependent.lastName}" styleClass="content"/>
</rich:column>
<rich:column style="width:120px;">
<f:facet name="header">
<h:outputText value="Date of Birth" styleClass="header" style="width:120px;"/>
</f:facet>
<h:outputText value="#{dependent.dob}" styleClass="content" >
<f:convertDateTime type="date" pattern="dd-MM-yyyy"/>
</h:outputText>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Relationship" styleClass="header"/>
</f:facet>
<h:outputText value="#{dependent.dependentType}" styleClass="content" style="width:90px;" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Gender" styleClass="header"/>
</f:facet>
<h:outputText value="#{dependent.gender}" styleClass="content" style="width:70px;" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Modify" styleClass="header" />
</f:facet>
<a4j:region>
<a4j:commandLink value="Modify" styleClass="content" title="Modify" render="EditDependentpanel dtab4" action="#{DependentManagedBean.getDependent()}" onbeforedomupdate="#{rich:component('EditDependentpanel')}.show()">
<a4j:param name="DependentID" value="#{dependent.dmsCertRequestDependentId}" assignTo="#{DependentManagedBean.mDmsCertRequestDependentId}"></a4j:param>
</a4j:commandLink>
</a4j:region>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Remove" styleClass="header"/>
</f:facet>
<a4j:region>
<a4j:commandLink value="Remove" styleClass="content" execute="@this" title="Remove"
oncomplete="#{rich:component('confirmPane')}.show()" >
<a4j:param value="#{dependent.dmsCertRequestDependentId}" assignTo="#{DependentManagedBean.mDmsCertRequestDependentId}"></a4j:param>
</a4j:commandLink>
</a4j:region>
</rich:column>
</rich:dataTable>
<a4j:jsFunction name="remove" action="#{DependentManagedBean.delete()}" render="DependentDataTable" execute="@this"
oncomplete="#{rich:component('confirmPane')}.hide();" />
</a4j:outputPanel>
<rich:popupPanel id="confirmPane" autosized="true">
Are you sure you want to Remove this Dependent?
<a4j:commandButton value="Cancel" onclick="#{rich:component('confirmPane')}.hide(); return false;" />
<a4j:commandButton value="Delete" onclick="#{rich:component('confirmPane')}.hide();remove(); return false;" render="DependentDataTable" />
</rich:popupPanel>
</td>
</tr>
</tbody>
</table>
<h:form>
When My ManagedBean is in Request scope , the a4j:commandLink doesn't invoke the action properly, even after changing the managed bean scope to ViewScope a4j:commandLink doesn't work
But when I changed to Session scope everything worked fine.Is there any way to make it work with Request Scope?
Regards,
Sabarinath -
3. Re: a4j:commandLink action not working in rich:datatable[richfaces 4.2.2]
healeyb Jun 17, 2012 12:13 PM (in response to sabarinathsss)It's this one that's not working?
<a4j:commandLink value="Modify" styleClass="content" title="Modify"
render="EditDependentpanel dtab4"
action="#{DependentManagedBean.getDependent()}"
onbeforedomupdate="#{rich:component('EditDependentpanel')}.show()">
<a4j:param name="DependentID"
value="#{dependent.dmsCertRequestDependentId}"
assignTo="#{DependentManagedBean.mDmsCertRequestDependentId}">
</a4j:param>
</a4j:commandLink>
a couple of things to check:
- what is javax.faces.STATE_SAVING_METHOD set to in web.xml
- what imports are you using for the *Scoped annotations
- Is it any better without the onbeforedomupdate
- have you got a <h:head> somewhere
- check for javascript errors, run with the javascript console on your browser (dev tools)
- is all the code you posted permanently resident in the DOM? it's not in something with rendered=
strange that it works with SessionScoped and not ViewScoped.
-
4. Re: a4j:commandLink action not working in rich:datatable[richfaces 4.2.2]
paul.dijou Jun 17, 2012 9:49 AM (in response to sabarinathsss)You can read that for more info : http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked
I think Brendan is right and it's because your bean is RequestScope. In order to make it works, you will have to repopulate your dataTable value list at each Ajax request. Or use a ViewScope.
-
5. Re: a4j:commandLink action not working in rich:datatable[richfaces 4.2.2]
sabarinathsss Jun 19, 2012 11:53 AM (in response to healeyb)Thanks to reply
Now a4j:commandLink was worked in ViewScope.
Can anyone please explain why it is not worked in RequestScope ?
Thanks
Advance
-
6. Re: a4j:commandLink action not working in rich:datatable[richfaces 4.2.2]
paul.dijou Jun 19, 2012 12:17 PM (in response to sabarinathsss)If you read : http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked , you should understand. Point 4 is probably the one which was blocking you :
If
UICommand
orUIInput
components are placed inside an iterating component like<h:dataTable>
,<ui:repeat>
, etc, then you need to ensure that exactly the samevalue
of the component is been preserved during the apply request values phase of the form submit request. JSF will namely reiterate over it to find the clicked link/button and submitted input values. Putting the bean in the view scope and/or making sure that you load the data model in (post)constructor of the bean (and thus not in the getter method!) should fix it.Since your bean was RequestScope, the list was reset at each request, which is no longer the case when you are using ViewScope.
Regards.
-
7. Re: a4j:commandLink action not working in rich:datatable[richfaces 4.2.2]
healeyb Jun 19, 2012 12:51 PM (in response to paul.dijou)The conclusion I was surprised to reach was that the scopes provided by both JSF and CDI fell far short of my expectations
in an ajax world. The fact that CDI didn't come with @ViewScoped was extremely unfortunate and this was one of the things
that Seam 3 addressed.
The problem was that there were loads of terminal compatibility problems between Seam 3 and Weld (the glassfish CDI
reference implementation) so I couldn't use it at the time.
Luckily I stumbled across Myfaces CODI which like Seam 3 is a CDI extensions package, and it provides many new scopes
such as @ViewAccessScoped. This scope ensures that a bean remains in scope until the next view loads which doesn't
reference it. Myfaces CODI runs fine on Mojarra. One of the things I've been able to do with @ViewAccessScoped is to
stop using view parameters, so rather than passing data between views as (unsecure) query parameters I just inject the
information dynamically into the required bean and it's there when the next page loads.
I believe that the present plan is for the Seam and CODI people to pool resources for which they have formed the
Apache DeltaSpike project, to bring together the best bits from each extensions project. This has to be a really good thing
and I suspect Brian Leathem knows a whole lot more about this than I do!
Regards,
Brendan.