ViewScope and Sorting?

UI Components for JSF
Post Reply
craig
Posts: 21
Joined: 04 Oct 2010, 16:09

23 Feb 2011, 13:15

Is is possible to use DataTable sorting when the bean is ViewScoped?

When I click sort, it calls into the backing bean that returns the same list, but the list is never sorted.

The getter for the property is never called?

I've tried with 2.2 and 2.2.1

Any ideas?

Thanks Craig

Code: Select all

		
			<h:form>
				<p:dataTable value="#{accountListBean.accounts}" var="account" > 
					<p:column sortBy="#{account.name}">
						<f:facet name="header">  
							<h:outputText value="Name" />  
						</f:facet>  
						<h:outputText value="#{account.name}" />
					</p:column>
					<p:column sortBy="#{account.url}">
						<f:facet name="header">  
							<h:outputText value="URL" />  
						</f:facet>
						<h:outputText value="#{account.url}" />
					</p:column>	
					<p:column  sortBy="#{account.createdAt}">
						<f:facet name="header">  
							<h:outputText value="Created At" />  
						</f:facet>
						<h:outputText value="#{account.createdAt}" />
					</p:column>	
				</p:dataTable>
			</h:form>

Code: Select all

@ViewScoped
@Named("accountListBean")
public class AccountListBean implements Serializable
{
   private static final long serialVersionUID = 1L;

   @Inject
   private AccountManager accountManager;

   private List<Account> accounts;

   @PostConstruct
   public void loadAccounts()
   {
      accounts = accountManager.list();
   }

   public List<Account> getAccounts()
   {
      return accounts;
   }
}
Last edited by craig on 23 Feb 2011, 22:38, edited 1 time in total.

MikeK
Posts: 103
Joined: 13 Oct 2010, 15:07

23 Feb 2011, 22:31

I can verifiy that sorting works when using an @ManagedBean with the @ViewScoped tag. I do not believe @Named beans have @ViewScoped so I assume you are using an extension. I do not see any sortable columns in your sample code either.
Prime Faces 6.0.14
Mojarra 2.2.14
Apache Tomcat 8.5.11
Internet Explorer 10,11

craig
Posts: 21
Joined: 04 Oct 2010, 16:09

23 Feb 2011, 22:40

Sorry my bad, I coppied the code after I have backed out the sort tags.

I will try with @ManagedBean annotation

Thanks for your help,

Craig

craig
Posts: 21
Joined: 04 Oct 2010, 16:09

23 Feb 2011, 22:45

Using managed bean i get the execption

Code: Select all

java.lang.RuntimeException: Use of @javax.faces.bean.ManagedBean is forbidden. Please use @javax.inject.Named instead

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 11 guests