我有一个if声明,我正在尝试使用JSTL.
我的代码如下(变量值是包含用户定义对象的ArrayList,类型是该对象的私有属性,使用公共getter/setter方法):
<c:forEach items="${list}" var="values">
<c:if test="${values.type}=='object'">
<!-- code here -->
</c:if>
</c:forEeach>
Run Code Online (Sandbox Code Playgroud)
test属性中部件的正确语法是什么.文档并没有真正帮助那部分http://download.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/index.html
谢谢.
我需要为<h:commandButton>while 创建一个回调作为参数,我需要传递一个与外部参数id字符串连接的参数:
我尝试嵌套一个这样的EL表达式:
<h:commandButton ... action="#{someController.doSomething('#{id}SomeTableId')}" />
Run Code Online (Sandbox Code Playgroud)
然而,由于EL异常,这失败了.这样做的正确语法/方法是什么?
public class LoginAction extends ActionSupport {
private String username;
private String password;
@Override
public String execute() throws Exception {
ActionContext ctx = ActionContext.getContext();
Integer counter = (Integer)ctx.getApplication().get("counter");
// put counter into application
ctx.getApplication().put("counter", counter);
// put username into session
ctx.getSession().put("user", username);
if (getUsername().equals("crazyit.org")
&& getPassword().equals("leegang")) {
ctx.put("tip", "Login Success! ");
return SUCCESS;
}
else {
ctx.put("tip", "Login Falied!");
return ERROR;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我把"counter"在应用"user"会话和"tip"中ActionContext.在JSP中,我可以使用${session.user}和${sessionScope.user}引用"user"属性.${request.tip}并${requestScope.tip}参考 …
每当我在JSP文件中工作并键入${以启动el(表达式语言)标记时,Eclipse将}在光标之后自动添加(在结束括号之前有一个空格),以便我得到${ }而不是${}.
我可以修改首选项中的代码模板以更改此行为,还是超出用户首选项控制?
我已经检查了Preferences:Web:JSP Files:Editor:Templates,但这些模板都不匹配.我还查看了偏好中的其他几个部分,但没有找到任何有希望的东西.
考虑下面的JSP:
<param name="FlashVars" value="${flashVars}" />
Run Code Online (Sandbox Code Playgroud)
${flashVars}包含&符号的值需要在输出之前进行编码.相反,JSP期望值为${flashVars}HTML的一部分,并逐字输出&符号,导致HTML错误.
我发现如果我像这样编写它,我可以得到要编码的值:
<param name="FlashVars" value="<c:out value="${flashVars}"/>" />
Run Code Online (Sandbox Code Playgroud)
但这看起来很丑陋,让我的IDE混乱.有没有更好的方法来获得相同的结果?
我在JSP代码中一直这样做:
<c:out value="${myVar}"/>
Run Code Online (Sandbox Code Playgroud)
今天我第一次意识到我似乎也能够使用这个更短的版本:
${myVar}
Run Code Online (Sandbox Code Playgroud)
没有<c:out>!
也许这是因为我的页面声明如下:
<%@ page language="java" contentType="text/html;
charset=utf-8" pageEncoding="utf-8" isELIgnored="false" %>
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是,我可以用<c:out>我的代码替换这个较短的版本吗?有没有理由继续使用<c:out>?还是有些地方我可能还需要它?
我正在使用JSF 2.0.我有一个托管bean,我可以通过我的xhtml页面访问.在bean内部,我声明了一个内部类.我可以访问ArrayList<String>托管bean但不能访问,ArrayList<InnerClass>我得到的错误是InnerClass没有可读属性.谁知道什么是错的?
当我使用f:selectItems来显示Map中的项目时,我无法显示Map项的值,只显示键.f:selectItems根本不使用itemLabel.当我使用List而不是工作.
以下确实使用itemLabel来显示List中项目的"描述":
<h:selectOneMenu>
<f:selectItems value="#{testBB.testList}" var="s"
itemLabel="TEST #{s.description}" itemValue="#{TEST s.name}" />
</h:
selectOneMenu>
Run Code Online (Sandbox Code Playgroud)
以下尝试在Map中显示项目的值不起作用.它显示项目的键,但不使用itemLabel属性,因为可以通过缺少"TEST"文本的输出来识别.
<rich:select>
<f:selectItems value="#{testBB.testMap}" var="s"
itemLabel="TEST #{s.value}" itemValue="TEST #{s.key}" />
</rich:select>
Run Code Online (Sandbox Code Playgroud)
使用的简单支持bean如下:
public class TestBB {
private Map<String, String> testMap;
private List<TestItem> testList;
public TestBB() {
testMap = new HashMap<String, String>();
testMap.put("1_key", "Item One");
testMap.put("2_key", "Item Two");
testMap.put("3_key", "Item Three");
testList = new ArrayList<TestItem>();
testList.add( new TestItem("name_1", "description_1") );
testList.add( new TestItem("name_2", "description_2") );
testList.add( new TestItem("name_3", "description_3") );
}
public Map<String, String> getTestMap() {
return testMap; …Run Code Online (Sandbox Code Playgroud) 在JSTL中,
<fmt:formatNumber value="${1.6}" type="number" pattern="#"/>
Run Code Online (Sandbox Code Playgroud)
返回2和以下
<fmt:formatNumber value="${1.4}" type="number" pattern="#"/>
Run Code Online (Sandbox Code Playgroud)
返回1,我需要2,一个数字的上限.
有没有直接的方法在JSTL中实现这一点(或者唯一的方法是使用适当的自定义标记)?
我有一个Map在EL中${map},我试图使用一个键来获取它的值,该键本身也是一个${key}带有值的EL变量"1000".
使用${map["1000"]}作品,但${map["$key"]}不起作用.我做错了什么,如何Map使用变量作为键来获取值?
el ×10
jsp ×7
jstl ×3
java ×2
jsf ×2
jsf-2 ×2
ceil ×1
eclipse ×1
html-encode ×1
if-statement ×1
managed-bean ×1
map ×1