对于专业人士来说这应该很容易:
我正在使用JSF/Facelets/Seam,我正在尝试显示radiobuttons.然后,在用户单击其中一个按钮后,应该保存该值并立即将用户重定向到另一个页面(即不需要单击提交按钮).
单选按钮有效,但不是转发.
谢谢
您确实可以使用Richfaces添加a4j:support组件:
<h:selectOneRadio value="#{myBean.myValue}" ...>
...
<a4j:support event="onclick" action="#{myBean.doSomething}"/>
</h:selectOneRadio>
Run Code Online (Sandbox Code Playgroud)
在您的Java代码中:
public String doSomething() {
// Your code goes here...
...
// Now, we move to the new page.
return "some-outcome";
}
Run Code Online (Sandbox Code Playgroud)
但是,如果您不能(或不想)添加新库,则可以通过旧方式执行此操作:
<h:selectOneRadio value="#{myBean.myValue}" ... onclick="this.form.submit();" valueChangeListener="#{myBean.doSomething}">
...
</h:selectOneRadio>
Run Code Online (Sandbox Code Playgroud)
当检测到onclick Javascript事件时,此代码将提交包含单选按钮的表单.在服务器端,将执行动作doSomething.在此方法中,您可以执行导航规则:
public void doSomething(ValueChangeEvent evt) {
// Your code goes here...
...
// Now, we move to another page...
FacesContext context = FacesContext.getCurrentInstance();
NavigationHandler navigation = context.getApplication().getNavigationHandler();
navigation.handleNavigation(context, "", "some-outcome");
}
Run Code Online (Sandbox Code Playgroud)
some-outcome是faces-config.xml中导航规则中定义的结果.
归档时间: |
|
查看次数: |
27183 次 |
最近记录: |