how to get the value in jstl
I 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.
Exception:
com.sun.facelets.tag.TagAttributeException: /role/MyPage.xhtml @33,82 value="#{roleManager.roleStatus(roleId)}" Error Parsing: #{roleManager.roleStatus(roleId)}
Code:
<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 val开发者_StackOverflow社区ue="123"> <h:outputLabel value="#{category.key}"/></option>
</c:forEach>
</select>
Standard el resolver cannot evaluate method invocation with parameters. Here are some solutions:
Using temp property in your bean:
<c:set target="${roleManager}" property="roleId" value="${roleId}"/>
<c:set var="roleIdValue" value="#{roleManager.roleStatus}" />
Also you will need add the following code to your bean:
private String roleId;
public String getRoleStatus() {
// Invocation of your logic with the parameter.
return getRoleStatus(getRoleId());
}
public String getRoleId() {
return roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
Using functions:
On page:
${prefix:methodName(param1, param2, ...)}
And you should declare the function in taglib:
<function>
<name>methodName</name>
<function-class>className</function-class>
<function-signature>
returnType methodName(param1Type, param2Type, ...)
</function-signature>
As parameters you can use your roleManager itself and the argument.
Using el-resolver which allows method invocations:
Use for example JBoss el resolver, or also you can implement your own solution as described here: http://technology.amis.nl/blog/622/how-to-call-methods-from-el-expressions-pre-jsp-20-trick-for-jsps-with-jstl
精彩评论