File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Looping in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Looping in JSF" Watch "Looping in JSF" New topic
Author

Looping in JSF

Praveen Yendluri
Ranch Hand

Joined: Apr 13, 2011
Posts: 33
Hi

Is there any JSF tag equivalent to <logic:iterate> tag because I have an AyyayList<Student> having Student Objects.

Student Object has it properties like name, number, address .....

If I want to loop those properties how can I do it in JSF.

I can use DataTable, but I dont want to display in tabular form. Is this possible with <ui:repeat> tag? If so, please provide me a sample code?

Please let me know the solution for this?

Thanks,
Praveen
Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

If you are using Facelet view Tech for the JSF development, try




look at these web sites for further reference
http://www.jsftoolbox.com/documentation/facelets/10-TagReference/facelets-ui-repeat.html
http://facelets.java.net/nonav/docs/dev/docbook.html#template-repeat

Tuna TÖRE


blog: http://tunatore.wordpress.com
SCJP 6.0 + SCWCD 1.5
Praveen Yendluri
Ranch Hand

Joined: Apr 13, 2011
Posts: 33
Hi Tuna,

I have tried as per your suggestion, but it is throwing below error. Do I need to configure this managed bean in faces-config.xml? I have used annotations here.

Error Parsing /index.xhtml: Error Traced[line: 30] The value of attribute "value" associated with an element type "null" must not contain the '<' character.

javax.faces.view.facelets.FaceletException: Error Parsing /index.xhtml: Error Traced[line: 30] The value of attribute "value" associated with an element type "null" must not contain the '<' character.
at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:387)
at com.sun.faces.facelets.compiler.SAXCompiler.doMetadataCompile(SAXCompiler.java:370)
at com.sun.faces.facelets.compiler.Compiler.metadataCompile(Compiler.java:123)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.createMetadataFacelet(DefaultFaceletFactory.java:353)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:231)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:164)
at com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:102)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:239)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:619)



My Managed Bean:

@ManagedBean
public class DynamicDataLoadGraph {

private DynamicDataLoadGraphObject ddlobj= null;
public DynamicDataLoadGraph(){
}
public ArrayList getReleasedData(){
ArrayList dataList = new ArrayList();

for(int i=0;i<10;i++){
ddlobj = new DynamicDataLoadGraphObject();
ddlobj.setGood(i+10);
ddlobj.setLate(i+30);
ddlobj.setWarned(i+25);
dataList.add(ddlobj);

}

return dataList;

}

My Value Object:

public class DynamicDataLoadGraphObject {

private int late = 0;
private int warned = 0;
private int good = 0;

public int getGood() {
return good;
}

public void setGood(int good) {
this.good = good;
}

public int getLate() {
return late;
}

public void setLate(int late) {
this.late = late;
}

public int getWarned() {
return warned;
}

public void setWarned(int warned) {
this.warned = warned;
}

}


Below is my sample code in Xhtml.

<ui:repeat value="#{dynamicDataLoadGraph.getReleasedData}" var="released">
<ui:repeat value="#{released.DynamicDataLoadGraphObject}" var="part">
setData (0,0,part.good);
setData (0,0,part.warned);
setData (0,0,part.late);
</ui:repeat>
</ui:repeat>

Please help me regarding this.

Thank you,
Praveen
Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

Try the code below, it will work as you expected
May be you can modify it, but first you should understand that two repeat tags are only required if you want to iterate like in two for statement




otherwise only one repeat tag is enough.

DynamicDataLoadGraph class


DynamicDataLoadGraphObject class



index.html class



Tuna TÖRE
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

I don't know why you don't want any tables. That output's going to wrap round and round the webpage in one big long paragraph. I would have at least made the deparment start a new line.

However, I can't spot anything wrong in your example. Which one of those xthml lines is "line 30"? That message usually comes from having a misplaced quote in the View source text.


Customer surveys are for companies who didn't pay proper attention to begin with.
Praveen Yendluri
Ranch Hand

Joined: Apr 13, 2011
Posts: 33
Hi Tuna,

Application is throwing error saying property "getReleasedData" not fund. My managed bean name is DynamicDataLoadGraph. I had called in XHTML as value="#{dynamicDataLoadGraph.releasedData}". Is this wrong?

javax.el.PropertyNotFoundException: /index.xhtml @18,80 value="#{dynamicDataLoadGraph.releasedData}": Property 'getReleasedData' not found on type com.samples.examples.DynamicDataLoadGraph


Thank you,
Praveen
Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

First change your classes by the above classes (because I have changed classes a little) then try again calling from xhtml page.
It will work as you expect, there are some typos inside your code...

Tuna TÖRE
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Looping in JSF
 
Similar Threads
jsf books
how can I use richfaces css in jsf tag.
Eclipse JSF ID Generator
setting delay time for tooltips with jsf html tags
jsp:forward and jsp:include