[英]JSF: navigation
I have to warn you: the question may be rather silly, but I can't seem to wrap my head around it right now. 我必须警告你:问题可能相当愚蠢,但我现在似乎无法绕过它。
I have two managed beans, let's say A and B: 我有两个托管bean,比方说A和B:
class A
{
private Date d8; // ...getters & setters
public String search()
{
// search by d8
}
}
class B
{
private Date d9; //...getters & setters
public String insert()
{
// insert a new item for date d9
}
}
and then I have two JSP pages, pageA.jsp (the search page) and pageB.jsp (the input page). 然后我有两个JSP页面, pageA.jsp (搜索页面)和pageB.jsp (输入页面)。 What I would like to do is placing a commandbutton in pageB so to open the search page pageA passing the parameter d9 somehow, or navigating to pageA directly after b.insert() .
我想要做的是在pageB中放置一个命令 按钮,以便打开搜索页面页面A以某种方式传递参数d9 ,或者在b.insert()之后直接导航到pageA 。 What I would like to do is showing the search result after the insertion.
我想要做的是在插入后显示搜索结果。
Maybe it's just that I can't see the clear, simple solution, but I'd like to know what the best practice might be here, also... 也许只是因为我无法看到清晰,简单的解决方案,但我想知道这里最好的做法是什么,也......
I though of these possible solutions: 我想这些可能的解决方案:
JSF 1.1/1.2 raw doesn't provide an easy way to do this. JSF 1.1 / 1.2 raw不提供简单的方法。 Seam/Spring both have ways around this and there are a couple of things you can do.
Seam / Spring都有办法解决这个问题,你可以做几件事。 JSF 2 should also have solutions to this once it is released.
一旦发布,JSF 2也应该有解决方案。
Probably the easiest and most expedient would be to collapse the two beans into one and make it session scoped. 可能最容易也是最方便的是将两个bean合并为一个并使其成为会话范围。 The worry, of course, is that this bean will not get removed and stay in session until the session times out.
当然,担心的是这个bean不会被删除并保持会话直到会话超时。 Yay Memory leaks!
耶内存泄漏!
The other solution would be to pass the date on as a GET parameter. 另一种解决方案是将日期作为GET参数传递。 For instance, you action method could call the
例如,你的动作方法可以调用
FacesContext.getCurrentInstance().getExternalContext().redirect("pageB?d9=" + convertDateToLong(d9));
and then get the parameter on the other side. 然后在另一侧获取参数。
You should configure the navigation flow in faces-config.xml. 您应该在faces-config.xml中配置导航流。 In ideal scenario you would return a "status" message which would decide the flow.
在理想情况下,您将返回“状态”消息,该消息将决定流程。 Read more at following link: http://www.horstmann.com/corejsf/faces-config.html http://publib.boulder.ibm.com/infocenter/rtnlhelp/v6r0m0/index.jsp?topic=/com.businessobjects.integration.eclipse.doc.devtools/developer/JSF_Walkthrough8.html
阅读以下链接: http : //www.horstmann.com/corejsf/faces-config.html http://publib.boulder.ibm.com/infocenter/rtnlhelp/v6r0m0/index.jsp?topic=/com。 businessobjects.integration.eclipse.doc.devtools /开发商/ JSF_Walkthrough8.html
As far as passing the values from one page to another is concerned you can use backing beans. 就将值从一个页面传递到另一个页面而言,您可以使用支持bean。 More about backing beans here: http://www.netbeans.org/kb/articles/jAstrologer-intro.html http://www.coderanch.com/t/214065/JSF/java/backing-beans-vs-managed-beans
有关支持bean的更多信息, 请 访问 : http : //www.netbeans.org/kb/articles/jAstrologer-intro.html http://www.coderanch.com/t/214065/JSF/java/backing-beans-vs-managed -豆子
Hope i have understood and answered correctly to your question 希望我已经理解并正确回答了你的问题
Way to share values between beans 在bean之间共享值的方法
FacesContext facesContext = FacesContext.getCurrentInstance();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext, expression, Object.class);
return valueExp.getValue(elContext);
In above code "expression" would be something like #{xyzBean.beanProperty}
Since JSF uses singleton instances, you should be able to access the values from other beans. 在上面的代码中,“expression”类似于
#{xyzBean.beanProperty}
因为JSF使用单例实例,所以你应该能够访问其他bean的值。 If you find more details on this technique, I am sure you'll get what you are looking for. 如果你找到关于这种技术的更多细节,我相信你会得到你想要的东西。
<h:commandLink action="#{b.insert}" value="insert"/>
FacesContext fc = FacesContext.getCurrentInstance();
FacesContext fc = FacesContext.getCurrentInstance();
fc.getExternalContext().getRequestMap().put("d9", d9);fc.getExternalContext()。getRequestMap()。put(“d9”,d9);
<from-outcome>return string of insert method</from-outcome>
<to-view-id>address of A</to-view-id>
in class A, when page is navigated, A should be initialized as it will be referenced. 在A类中,当导航页面时,应该初始化A,因为它将被引用。
FacesContext fc = FacesContext.getCurrentInstance();
FacesContext fc = FacesContext.getCurrentInstance();
fc.getExternalContext().getRequestMap().get("d9", d9);fc.getExternalContext()。getRequestMap()。get(“d9”,d9);
Sorry i cant give full code, as i have no ide at here, its internet machine at work. 对不起,我不能给完整的代码,因为我在这里没有ide,它的互联网机器在工作。 I could not give details therefore.
因此我无法提供细节。
In my opinion, the simplest way is 3-rd option - have both query and insert methods in same class. 在我看来,最简单的方法是第3个选项 - 在同一个类中同时使用查询和插入方法。 And you can do something like that:
你可以这样做:
public String query () {
//...
}
public String Insert() {
//insert
return Query(); }
If your classes are managed Beans you can load class A from class B and call A.query() in your insert method at the end. 如果你的类是托管Beans,你可以从B类加载A类,并在最后的insert方法中调用A.query() 。 Also class A can have
A级也可以
<managed-bean-scope>session</managed-bean-scope>
parameter in faces-config.xml and it wouldn't be instantiated again when loaded. faces-config.xml中的参数,加载时不会再次实例化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.