JSF: CommandLink not working with dataTable and ajax
I have a commandLink inside a dataTable. dataTable is populated by an ajax call. But my commandLink is not pointing to the correct location. Here is the code.
<h:form id="form1">
<h:outputLa开发者_开发知识库bel value="Search Movie: " /> <h:inputText value="#{movieBean.movie.name}" id="inputName">
<f:ajax render="dTbl" listener="#{movieBean.searchMovie}" execute="inputName" />
</h:inputText><br/>
<h:commandButton type="reset" value="Clear" />
<h:dataTable id="dTbl" value="#{movieBean.movies}" var="movies" rendered="#">
<h:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:commandLink action="#{movieBean.loadMovieDetails}">
<h:outputText value="#{movies.name}" />
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="ISBN" />
</f:facet>
<h:outputText value="#{movies.isbn}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Release Date" />
</f:facet>
<h:outputText value="#{movies.releaseDate}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Star Rating" />
</f:facet>
<h:outputText value="#{movies.starRating}"></h:outputText>
</h:column>
</h:dataTable>
</h:form>
Any help is really appreciated. Thanks Imad
Put the bean in the view scope.
@ManagedBean
@ViewScoped
public class MovieBean {
// ...
}
And ensure that you don't do any business logic in the getters. So they should all look like this
public List<Movie> getMovies() {
return movies;
}
Yes, just a return propertyName;
and nothing more. If you need to, do it somewhere else.
Both will ensure that the list of movies is exactly the same during the form submit request as it was during the request which displayed the list. This way JSF can find the commandlink responsible for the action and execute it accordingly.
See also:
- JSF ignores
action
attribute
精彩评论