我正在为我的项目使用以下内容:Spring 3.0.1 + Apache Tiles 2.2.1 + Glassfish 2.1.我想要做的是在jsp页面中调用一些方法并将一些参数传递给它.例如,我有一个bean:
@Component
@Scope(value = "singleton")
public class TestBean {
public void test(String param){
System.out.println("param = " + param);
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个jsp页面:
<%@page contentType="text/html; charset=utf-8"%>
${testBean.test("hello")}
Run Code Online (Sandbox Code Playgroud)
这段代码给了我一个例外:
org.apache.jasper.JasperException:当未指定默认命名空间时,函数test必须与前缀一起使用
如果我调用一些方法而不传递参数 - 一切都OK.
我试图把的jboss-el.jar在我的WEB-INF/lib目录,并把所需的参数在web.xml(如解释在这里),但没有效果.
我仅限于上面列出的一组技术,因此我无法添加任何内容,或者,例如,无法更改我的app-server版本.
在所有这些条件下,我的问题是否有解决方案?
我已经阅读了有关通过actionListener将参数从jsf页面传递给managedbean的信息.是否也可以将参数传递给简单的操作方法?
谢谢你的阅读......
谢谢你们的建议!没有你我会迷路的:-)
以下为我工作:
<h:commandLink id="link" action="#{overviewController.showDetails}" >
<f:setPropertyActionListener target="#{overviewController.show_id}" value="#{project.id}" />
<h:outputText value="#{project.title}" />
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
那么现在谁值得绿色蜱?:-P我可以给他们两个吗?
我有一个如下命令按钮.
<h:commandButton value="Accept orders" action="#{acceptOrdersBean.acceptOrder}"
styleClass="button" rendered="#{product.orderStatus=='N' }"></h:commandButton>
Run Code Online (Sandbox Code Playgroud)
即使product.orderStatus值等于'N'命令按钮也不会显示在我的页面中.
这product.orderStatus是一个角色属性.
为了替换默认的Spring安全登录表单,我提出了这个解决方案:
<form name="f" action="../j_spring_security_check" method="POST" >
<h:panelGrid columns="2">
<h:outputText value="Username" />
<h:inputText id="j_username" />
<h:outputText value="Password" />
<h:inputText id="j_password" />
</h:panelGrid>
<h:commandButton value="Login" />
</form>
Run Code Online (Sandbox Code Playgroud)
但是<form>我想使用普通标签而不是普通标签,<h:form>因为Primefaces组件只能在其中工作<h:form>.使用<h:form>表单操作将由JSF自动设置到当前页面,而不是上面示例中我设置的值."../j_spring_security_check"现在我必须在哪里编写动作?我尝试将其放入<h:commandButton>如下,但这不起作用:
<h:form name="f">
<h:panelGrid columns="2">
<h:outputText value="Username" />
<h:inputText id="j_username" />
<h:outputText value="Password" />
<h:inputText id="j_password" />
</h:panelGrid>
<h:commandButton value="Click here" action="../j_spring_security_check" />
</form>
Run Code Online (Sandbox Code Playgroud)
它会导致错误消息Unable to find matching navigation case with from-view-id '/login.xhtml' for action '../j_spring_security_check' with outcome '../j_spring_security_check'.
这是定义导航案例的唯一方法faces-config.xml …
我正在使用数据表,每行我有两个按钮,一个是"编辑"和一个"删除".
如果所讨论的行符合某个条件,我需要这些按钮是只读的,即禁用.我在JSF 2中看到,可以将参数传递给方法调用.在JSF 1.2中有什么相同的东西吗?
理想情况下我想要的东西(循环变量是循环,还有另一个bean,helper,它包含我想调用的方法):
<h:commandButton value="Edit"
disabled="#{helper.isEditable(loop.id)}" />
Run Code Online (Sandbox Code Playgroud)
在这种情况下,向bean 添加isEditable属性并不具有语义意义,并且在bean周围创建包装器对象是不切实际的.
提前致谢.
我正在尝试实现一个用户名列表,可以通过单击UP或DOWN链接重新排列.
<ul>
<ui:repeat var="user" value="#{cc.attrs.value}">
<li>
#{user.name}
<h:link outcome = "user" value = "left" onclick="#{accountController.moveDown}">
<f:param name="id" value = "${user.id}" />
</h:link>
</li>
</ui:repeat>
</ul>
Run Code Online (Sandbox Code Playgroud)
这里的问题是我似乎没有正确使用onclick属性.这样做的正确方法是什么?
编辑:根据您的建议,我将所有链接放在一个表单中:
<h:form>
<ui:repeat value="#{cc.attrs.value}" var = "user">
<div class = "user">
<h:commandLink id = "Link1" value = "Up" binding = "#{accountController.ommandLink}" action = "#{accountController.moveUserUp}">
<f:attribute name = "userId" value = "#{user.id}" />
</h:commandLink>
<h:commandLink id = "Link2" value = "Down" binding = "#{accountController.commandLink}" action = "#{accountController.moveUserDown}">
<f:attribute name = …Run Code Online (Sandbox Code Playgroud) 我想将java arraylist显示到JSF页面中.我从数据库生成了arraylist.现在我想通过索引号调用列表元素索引将列表显示到JSF页面.是否可以直接从JSF页面中的EL表达式向bean方法传递参数并显示它?
我在JSF项目中使用Passthrough元素,并且需要执行以下操作:
<h:commandLink action="#{myBean.acao()}" value="click me">
<f:setPropertyActionListener target="#{myBean.object}" value="#{localObject}"/>
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
但是使用Passthrough元素可以更好地控制前端,例如尝试以下操作:
<a href="#" jsf:action="#{myBean.acao()}">click me
<f:setPropertyActionListener target="#{myBean.object}" value="#{localObject}"/>
</a>
Run Code Online (Sandbox Code Playgroud)
但显然这不起作用,我收到以下错误消息:
<f:setPropertyActionListener> Parent is not of type ActionSource, type is: com.sun.faces.component.PassthroughElement
Run Code Online (Sandbox Code Playgroud)
有谁知道我该怎么解决?
我们在这里有一个(在我们的观点中)非常简单的场景.但是我们在复合组件和f:属性标签上遇到了问题.我会尽量保持代码尽可能简单.
复合组件:
<cc:interface name="button">
...
<cc:attribute
name="actionListener"
required="true"
method-signature="void f(javax.faces.event.ActionEvent)"
target="button"
shortDescription="The action listener for this button." />
...
</cc:interface>
<cc:implementation>
<ice:commandButton
...
actionListener="#{cc.attrs.actionListener}"
...>
<cc:insertChildren />
</ice:commandButton>
</cc:implementation>
Run Code Online (Sandbox Code Playgroud)
...现在我们使用这样的组件:
<ctrl:button
...
actionListener="#{bean.method}"
...>
<f:attribute name="objectId" value="#{someObject.id}" />
</ctrl:button>
Run Code Online (Sandbox Code Playgroud)
现在我们需要访问动作侦听器方法中的"objectId"属性.我们已经尝试过这样的事情了:
public void method(ActionEvent event)
{
...
event.getComponent().getAttributes().get("objectId");
...
}
Run Code Online (Sandbox Code Playgroud)
但属性映射不包含objectId.这种方法有什么问题吗?解决此问题的推荐方法是什么?
如果有人可以帮助我们,那会很好.
谢谢!阿姆
我正在使用Glassfish 3.1.2.2和JSF Mojarra 2.1.6.
我有以下Facelets页面:
<h:form>
<h:commandLink value="link">
<f:actionListener binding="#{backingBean.someMethod(1)}"/>
</h:commandLink>
</h:form>
Run Code Online (Sandbox Code Playgroud)
以下支持bean:
@RequestScoped
@ManagedBean
public class BackingBean {
public void someMethod(int i) {
System.out.println("It was called: " + i);
}
}
Run Code Online (Sandbox Code Playgroud)
当我单击链接时,控制台中出现"Info:It called called:1".
binding读取文档:
图书馆:http://xmlns.jcp.org/jsf/core,http://java.sun.com/jsf/core(Jsf Core)
标签:actionListener
捆绑
值绑定表达式,其值为实现javax.faces.event.ActionListener 的对象.[强调我的]
此外,该问题的接受答案表明,f:actionListener调用任意方法是不可能的.
如果不支持,为什么调用backing bean方法?