将值从页面传递到其他页面JSF [英] Passing Values from page to other page JSF

查看:44
本文介绍了将值从页面传递到其他页面JSF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java服务器界面(JSF)的初学者,我需要将文本输入的内容传递给第二页才能显示它,第二页也是如此:我想将单选按钮值传递给第三页.我搜索并尝试了很多但没有成功. 例如,我尝试过

I am beginner in java server faces (JSF), I need to pass the content of text input to second page to display it, the same applies for the second page: I want to pass radio buttons values to a third page. I searched and tried a lot without success. For example I tried

 <h:commandButton value="Next" action="#{myBean.execute(input_id.value)}"/>

执行方法是:

public void execute(String value) {
// ...

    try{
         FacesContext.getCurrentInstance().getExternalContext().dispatch("/Quizy.xhtml?faces-redirect=true");
    }
    catch(Exception e){
        System.out.println("err");    
    }  
}

有什么建议吗?

推荐答案

执行此操作的方法有多种,但这是其中一种. 您将需要将inputText值保存到bean的属性中,并且h:inputTexth:commanButton都应位于同一h:form元素中

There are several ways for doing this, but here is one of them. You will need to save the inputText value into a property of your bean and both your h:inputText and your h:commanButton should be in the same h:form element

这是示例代码

您认为

<h:form>
    ...
    <h:inputText value={myBean.someValue} />
    ....
    <h:commandButton value="Next" action="#{myBean.execute()}"/>
</h:form>

如果您希望属性( someValue )在不同页面中可用,则

您的托管bean至少应具有 session作用域.托管Bean的内容也应如下所示:

Your managed bean should be at least session scoped if you want your property (someValue) to be available in different pages. The content of the managed bean should look like this also:

private String someValue;

// Getter and setter for `someValue`

public String execute() {
    // ...
    return "/Quizy.xhtml?faces-redirect=true";
}

如果要检索该值,请在第二页中使用#{myBean.someValue}

In the second page if you want to retrieve that value, just use #{myBean.someValue}

这篇关于将值从页面传递到其他页面JSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆