• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get the value in jstl

 
sana shah
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have written a piece of code in jstl . I am getting the following error while executing the html.

Can I call a method in value attribute for c:set.If not please assit me how to do this.

com.sun.facelets.tag.TagAttributeException: /role/MyPage.xhtml @33,82 value="#{roleManager.roleStatus(roleId)}" Error Parsing: #{roleManager.roleStatus(roleId)}

<select name="123">
<c:forEach items="#{roleManager.addRoleList}" var="category">
<c:set var="roleId" value="#{category.value}" />
<c:set var="roleIdValue" value="#{roleManager.getRoleStatus(roleId)}" />
<c:if test="${roleIdValue}">
<option value="#{roleId}" style="color:#990000;"> <h:outputLabel value="#{category.key}" /></option>
</c:if>
<option value="123">
<h:outputLabel value="#{category.key}"/></option>
</c:forEach>
</select>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask JSF questions in the JSF forum. I have moved this post there for you.
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case you're wondering why the moderators are playing ping-pong with your question, it's because you're mixing JSF and JSTL. Don't do that. If you're using JSF you don't need JSTL and if you try and use it anyway, it will only cause you trouble.
 
Rob Micah
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:In case you're wondering why the moderators are playing ping-pong with your question, it's because you're mixing JSF and JSTL. Don't do that. If you're using JSF you don't need JSTL and if you try and use it anyway, it will only cause you trouble.

If that's the case then how do you go about creating a for-each construct using only jsf?
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Micah wrote:
Tim Holloway wrote:In case you're wondering why the moderators are playing ping-pong with your question, it's because you're mixing JSF and JSTL. Don't do that. If you're using JSF you don't need JSTL and if you try and use it anyway, it will only cause you trouble.

If that's the case then how do you go about creating a for-each construct using only jsf?


You don't. Logic goes in the backing bean (Model), not in the View. That's fundamental MVC practice, and you violate it at your peril, since not only aren't you going to find framework support, but it turns application maintenance into a "treasure hunt", because the location of user-code functionality is no longer predictable.

The JSF dataTable and ui:repeat constructs are intended to output a set of view elements (table rows for dataTable, arbitrarily complex sub-items in ui:repeat). The fact that you can construct ui elements like these by iteration is beside the point, since what they really are are 2-dimensional constructs rendered from collections, and if you happen to be running on a MegaTron 32000 system that can do parallel JSF object rendering, the results will be indistinguishable from what its poorer relations did using loops.
 
Rob Micah
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if you have a variable number of parameter elements to display to the user?
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Micah wrote:What if you have a variable number of parameter elements to display to the user?


"parameters" are logic, and logic doesn't belong in the view.

Going back to your original example, you're trying to build an HTML SELECT the hard way.

JSF has a control corresponding to the HTML SELECT and it's "selectOneMenu". Usage is as follows:


The getRoleList() method should return an array or sequential Collection (for example, a List) of javax.faces.SelectItem objects. You can construct them using the following logic in your backing bean:



For performance reasons, you should only build this list when it changes and cache the list so that the getRoleList() doesn't rebuild it on each of the 6 or 7 calls that will be made on a typical page render.

I've taken some liberties because your original object arrangements were a little hard to follow. The above example assumes that each role definition has a corresponding object containing an ID and a description suitable for SELECT OPTION value and label.
 
Rob Micah
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you might be confusing me with the original poster. What I'm talking about is a little different but I would like your input on it. I have a variable number of parameters that will be presented as inputs. Here is how I'm doing it now:



In the bean I have 2 Lists of Strings where each name/value pair is stored in a Map as well.

Also, when I say "parameters", I'm not talking about parameters in the request. I'm using it in as a general term for data I want to collect from the user.
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By golly, you're right. We left poor old Sana behind somewhere.

But you do have one thing in common, with Sana and that's mis-coded definitions . Take a look at the JavaDocs for the "h:inputText" control. See a "name" attribute there? I don't. That's because JSF isn't just a thin wrapper for HTML, it's a complete framework, and a part of that framework is that it takes total responsibility for getting data into and out of your backing beans. "name" isn't required, because the connection is via your databinding ("value") attribute.

There are 2 ways to handle what you're doing. I think probably you can get by with just using a dataTable with an inputText control in each row. Thanks to the magic of CSS, a dataTable can be made virtually indistinguishable from an HTML unordered list as far as on-screen appearance is concerned. And in fact, I've seen some non-java/non-JSF sources recommend retiring the old HTML ul and ol tags in favor of CSS anyway.

A simple dataTable is sufficient if you have an ordered collection or array to model the rows. And in most cases, even when you're modelling random data objects, you can glue them into a DataModel with maybe a little help from the setup and action methods.

When you want something more dynamic, you can go whole-hog, provide a container object that has a UI binding, then have your backing bean construct the UI contents by sheer brute force. Not something you want to do lightly, however. I've done it exactly once, in fact.
 
Rob Micah
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say brute force do you mean creating a custom UIComponent or something else?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!