aspose file tools
The moose likes JSF and the fly likes Error while working with JSF SelectOneMenu and JSTL forEach Tag    Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Error while working with JSF SelectOneMenu and JSTL forEach Tag    " Watch "Error while working with JSF SelectOneMenu and JSTL forEach Tag    " New topic
Author

Error while working with JSF SelectOneMenu and JSTL forEach Tag

Saravanan Vijayappan
Ranch Hand

Joined: Jan 02, 2007
Posts: 47
Hello,

I am new to JSF. I have set up few things in ArrayList in my contextListener as like below

ServletContext context=event.getServletContext();
List list=new ArrayList();
list1.add("Honda");
list1.add("Mazda");
list1.add("eClipse");
context.setAttribute("carList", list)

I just wanted to display the list in my JSF page, I wrote the below statements in my JSF page


<h:selectOneMenu value="{com.carSelection}">
<c:forEach var="car" items="${applicationScope.carList}" >
<f:selectItem itemLabel="${car}"/>
</c:forEach>
</h:selectOneMenu>

I am getting the below exception

org.apache.jasper.JasperException: /pages/protected/cmt/index.jsp(23,2) According to TLD or attribute directive in tag file, attribute itemLabel does not accept any expressions
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1124)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:819)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1512)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:838)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1512)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator


Could some one help to solve this error (Or) How should I display from my applicationScope list into MenuItems ?


Cheers,<br />Sarav
A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
You are mixing up JSTL and JSF tags. Not sure if this will work.
One way to do this is to use f:selectItems instead of c:foreach and f:selectItem, but you should create a SelectItem List from your carsList.
Another way if you are using Tomahawk is to use t:selectItems in which case you can directly use carsList. Tomahawk will convert the list to SelectItem list for you. Check out the MyFaces documentation and the wiki page.

Saravanan Vijayappan
Ranch Hand

Joined: Jan 02, 2007
Posts: 47
Thank you for your reply.

Unfortunately, In JSF 1.2 RI, the UI <f:selectItems> does not have the attribute "var", so, the below code does not work. I think, this can't be done JSF1.2 UI. As you suggested, I might need to add Tomahawk into my application. Please let me know if there are any other solutions. I am using richfaces with JSF1.2 RI

===============================================================
<h:selectOneMenu value="{com.carSelection}">
<f:selectItems var="#{applicationScope.carsSelectItemList}" />
</h:selectOneMenu>

or

<h:selectOneMenu value="{com.carSelection}">
<t:selectItems var="#{applicationScope.carList}" />
</h:selectOneMenu>
==================================================================
A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
I meant to say 'value' not 'var'. Try it again now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error while working with JSF SelectOneMenu and JSTL forEach Tag
 
Similar Threads
jsf:datatable with selectManyCheckbox problem
New to JSP
can't find file tad lib descriptor:"http://java.sun.com/jstl/core"
JSTL installation
General problems with some beginner stuff