我想使用数据库列创建链接.我有一个支持bean,我正在连接到数据库.连接没有问题,链接名称也没有问题.我可以在浏览器上看到我的链接.我想使用onclick函数,这正是问题开始的地方.我如何使用或可以在onclick中使用EL?
一个小例子:
<h:dataTable rows="7" value="#{frontSiteMenu.links}" var="row"
styleClass="sitemenu" width="200">
<h:column>
<a href="#" onclick="dispNewsGroup('${row.newsGroupId}')"><h:outputText value='#{row.newsGroup}' /></a>
</h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)
谢谢.
我注意到了JSF EL的这种行为.1.
<h:panelGroup rendered="#{!admissionBean.requestStatus=='PR'}">
..some buttons without rendered attribute
</h:panelGroup>
Run Code Online (Sandbox Code Playgroud)
2.
<h:inputText size="6" value="#{dimension.newWeight}" disabled="#{admissionBean.requestStatus=='PR'}"></h:inputText>
Run Code Online (Sandbox Code Playgroud)
1未呈现.2.文本框未禁用.
两者如何一起发生?文本框未禁用意味着requestStatus不等于PR.这意味着面板组的呈现条件应该是真的.
有什么帮助吗?我错过了这里的任何东西.
谢谢
我想在JSP中使用带有参数的EL的方法.但EL不支持方法中的参数.实际上我想显示一个表,它有一个输出一个单元格中的值列表的字段.对于每个单元格,此列表将不同,这取决于参数.我怎么能用EL做到这一点?
我试过这个,但是说它无法<c:set var="group" value="${entrant.idGroup}" />
在entrant.idGroup
返回int值的地方将Integer转换为String
<c:forEach var="entrant" items="${bean.entrants}">
<tr>
<td>${entrant.idEntrant}</td>
<c:set var="group" value="${entrant.idGroup}" />
<td><%=bean.getGroupCode(Integer.parseInt((String)pageContext.getAttribute("group")))%></td>
<td>${entrant.name}</td>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
但即使它有效,我也想在JSP中使用纯EL.我怎样才能做到这一点?
我正在做一个简单的注销,并希望确保我正确引用登录根.
<h:form>
<h:commandLink value="Logout" action="#{request.contextPath}/#{userController.logout()}" />
</h:form>
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
/topnav.xhtml @16,104 action="#{request.contextPath}/#{userController.logout()}" Not a Valid Method Expression: #{request.contextPath}/#{userController.logout()}
Run Code Online (Sandbox Code Playgroud)
UPDATE
现在我正在从登出链接添加导航规则到登录页面,因为登出链接在所有页面上,我需要添加规则以允许转换回登录页面.这似乎是一个简单的项目的很多配置.我希望只是让被调用的方法指示登录页面是最终目的地并且热门必须将导航条目从所有页面放入登录页面.
我怎样才能将一个arugument传递给听众方法?
我试过这样的:
<p:poll interval="3" listener="#{vehicleController.onPoll('12')}"
update="vehicleDataList"/>
Run Code Online (Sandbox Code Playgroud)
和
<p:poll interval="3" listener="#{vehicleController.onPoll(vehicle.vehicleLicense)}"
update="vehicleDataList"/>
Run Code Online (Sandbox Code Playgroud)
但它抛出以下异常:
javax.servlet.ServletException: /monitorVehicles/vehiclesList.xhtml
Failed to parse the expression [#{vehicleController.onPoll('12')}]
Run Code Online (Sandbox Code Playgroud)
我怎么能得到这个?
我正在尝试做一些非常简单的事情。我只想在 Spring MVC 应用程序中的 JSP 页面上显示一个列表。我在谷歌上搜索了很多,有很多例子(包括 Stackoverflow 上的一些),但它对我不起作用。我正在使用 Maven 和 Spring 3.2.4。这些是我的文件:
项目.java
public class Item
{
private final String value;
public Item(String value)
{
this.value = value;
}
public String getValue()
{
return value;
}
}
Run Code Online (Sandbox Code Playgroud)
主控制器.java
@Controller
public class MainController
{
@RequestMapping("/")
public String home(ModelMap map)
{
final List<Item> items = new ArrayList<Item>();
items.add(new Item("Value 1"));
items.add(new Item("Value 2"));
items.add(new Item("Value 3"));
items.add(new Item("Value 5"));
map.addAttribute(items);
return "list";
}
}
Run Code Online (Sandbox Code Playgroud)
列表.jsp
<!DOCTYPE html>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个JSF应用程序.我面临以下例外:
javax.el.ELException:不是有效的方法表达式
它所指的行如下:
<h:commandButton action="#{Login.trylogin} "value="#{messages.click}"/>
Run Code Online (Sandbox Code Playgroud)
我也尝试过#{Login.trylogin()}
,但结果是一样的.后面的bean #{Login}
有以下方法:
public String trylogin()
Run Code Online (Sandbox Code Playgroud)
在我faces-config.xml
的导航案例是这一个:
<navigation-rule>
<from-view-id>login.jsp</from-view-id>
<navigation-case>
<from-action>#{Login.login}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>readPW.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{Login.login}</from-action>
<from-outcome>failed</from-outcome>
<to-view-id>register.jsp</to-view-id>
</navigation-case>
Run Code Online (Sandbox Code Playgroud)
注意:这是一个学校项目,所以我不能使用其他方式进行导航,例如隐式导航.
我正在尝试为按钮创建JSF 2.1复合组件:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jstl/core">
<composite:interface>
<composite:attribute name="id" required="true" type="java.lang.String" />
<composite:attribute name="label" required="true" type="java.lang.String" />
<composite:attribute name="action" method-signature="java.lang.String action()" targets="#{cc.attrs.id}" />
</composite:interface>
<composite:implementation>
<a4j:commandLink id="#{cc.attrs.id}">
<span style="linkButton"><h:outputText value="#{cc.attrs.label}" /></span>
</a4j:commandLink>
</composite:implementation>
</html>
Run Code Online (Sandbox Code Playgroud)
我对此代码的问题是,在呈现页面时它会给出以下异常:
java.lang.ClassCastException: javax.faces.component.UINamingContainer cannot be cast to javax.faces.component.ActionSource2
at com.sun.faces.application.view.FaceletViewHandlingStrategy$MethodRetargetHandlerManager$ActionRegargetHandler.retarget(FaceletViewHandlingStrategy.java:1536)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.retargetMethodExpressions(FaceletViewHandlingStrategy.java:689)
at com.sun.faces.facelets.tag.jsf.CompositeComponentTagHandler.applyNextHandler(CompositeComponentTagHandler.java:201)
at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:196)
...
Run Code Online (Sandbox Code Playgroud)
当我用一个定义的String 替换#{cc.attrs.id}
in id
和targets
属性时,myId
组件按预期工作,但这使得它不能在同一页面中重复使用,从而消除了创建复合组件的神奇感.
我在这里错过了吗?
有没有办法获得JSF bean方法的调用层次结构,包括eclipse中的表达式语言调用?
我有一个简单的豆子:
@ManagedBean
@ViewScoped
public class MyBean {
public String getHello() {
return "Hello";
}
}
Run Code Online (Sandbox Code Playgroud)
还有一个简单的JSF页面:
<h:outputText value="#{myBean.demo}" />
Run Code Online (Sandbox Code Playgroud)
用CTRL点击#{myBean.demo} eclipse会显示getter.
但getHello()的调用层次结构不显示EL调用.
有没有办法看看是否在任何JSF页面中使用了getter?
我想输出一个primefaces数据表.
<p:dataTable var="bi" value="#{ bowlingInfo.hallMastaren} ">
<p:column headerText="Position">
<h:outputText value="#{bi.position }" />
</p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)
但它不会识别它看起来的数据,并抛出以下异常.
javax.servlet.ServletException:/test.xhtml @ 13,47 value ="#{bi.position}":在类型java.lang.String上找不到属性'position'
我正在使用primefaces 5.1.
删除<h:outputText value="#{bi.position }" />
将呈现页面.但它只会渲染一次行.由于我添加了两条记录,所以它期望它呈现两行.
下面的 EL 值表达式是否有效?
<p:selectBooleanCheckbox value="#{!bean.isCreateGroup}" id="checkBoxCreateSecurityGrpKey">
Run Code Online (Sandbox Code Playgroud)
我收到的错误是
javax.el.PropertyNotWritableException:/pages/popup.xhtml @503,170 value="#{!bean.isCreateGroup}": Illegal Syntax for Set Operation
Run Code Online (Sandbox Code Playgroud) 我正在尝试在JSP中将列表的内容打印为单个字符串,并用逗号分隔。
<div>${myList.stream().map(e->e.getStringValue()).collect(Collectors.joining(", "))}</div>
Run Code Online (Sandbox Code Playgroud)
我收到错误:
javax.el.MethodNotFoundException: Method not found: class org.apache.el.stream.Stream.collect(null)
Run Code Online (Sandbox Code Playgroud)
为什么Tomcat使用它自己的版本Stream
?有没有一种方法可以避免这种情况,并确保当我将它们放在JSP的EL中时,我在java类中编写的内容具有相同的行为?
我找到了这个答案/sf/answers/3005143991/ 但这不能解决我的问题。它使用Tomcat Streams的自定义方法。
我试图从这样的资源中获取图像:
<img src="#{resource['img/bla.svg']}"/>
Run Code Online (Sandbox Code Playgroud)
像这样工作
但是现在我想对此文件进行一般化,因此它将来自这样的java类:
LogoHandler.getLogo(String type)
Run Code Online (Sandbox Code Playgroud)
我试图像这样将它们放在一起:
<img src="#{resource["#{logoHandler.getLogo("A1")}"]}"/>
Run Code Online (Sandbox Code Playgroud)
但是它当然不起作用,只是为了向您展示我想要达到的目标。
你能帮我吗?