Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Looping in JSF

 
Praveen Yendluri
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Praveen Yendluri
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18009
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Praveen Yendluri
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic