命令链接操作参数未显示在JSF2中
在Liferay-Faces Portlet上,我想从一个.xhtml页面导航到另一个.xhtml页面传递参数,以便此第二页显示传递的参数。由于我不想对要通过的参数提供任何线索,因此我决定根据邮政请求来解决该任务,因此我选择使用a< h:commandlink>特征。
faces-config.xml:
<managed-bean>
<managed-bean-name>bUser</managed-bean-name>
<managed-bean-class>es.my.samples.UserBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>WEB-INF/views/index.xhtml</from-view-id>
<navigation-case>
<from-action>#{bUser.viewDetailsAction}</from-action>
<from-outcome>action-view-details</from-outcome>
<to-view-id>WEB-INF/views/result1.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
page1(index.xhtml):
<h:form>
<h:commandLink value="commandLink" action="#{bUser.viewDetailsAction()}">
<f:param name="id" value="13" />
</h:commandLink>
</h:form>
page2(resuct.2.xhtml):
<h:panelGrid columns="2">
<h:outputLabel value="Requested id: " />
<h:outputText value="#{bUser.id}" />
</h:panelGrid>
viewScoped bean(userbean.java):
@ManagedBean(name = "bUser")
@ViewScoped
public class UserBean {
private String id;
public UserBean() {
logger.trace("bean created");
}
@PostConstruct
public void postConstruct() {
logger.trace("start");
logger.trace("this.id:" + this.id);
}
public String getId() {
return id;
}
public void setId(String id) {
logger.trace("start [id]:" + id);
this.id = id;
}
@PreDestroy
public void preDestroy() {
logger.trace("start");
logger.trace("this.id:" + this.id);
}
public String viewDetailsAction() {
String _return = "action-view-details";
Map<String,String> params =
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
this.id = params.get("id");
logger.trace("this.id:" + this.id);
return _return;
}
将URL设置为http:// localhost:8080/web/web/guest/mission < /code>,当我按“命令链接”链接时,我将在屏幕上显示以下错误消息(翻译):
无法找到视图ID的匹配导航案例'/web-inf/views/index.xhtml',用于{2}。
如果我省略 faces-config.xml file file line &lt; from-action&gt;#{buser.viewdetailsaction}&lt;/from-from-action&gt;
,然后导航进行执行,但该页面并未显示传递的参数,尽管该参数是从JSF params
对象中提取的,并且由于某种render_ressponse的结果
阶段开始一旦完成方法完成,可以在显示的日志上看到:
[TRACE] UserBean:<init>():start
[TRACE] UserBean:<init>():this.id:null
[TRACE] UserBean:<init>():bean created
[TRACE] UserBean:postConstruct():start
[TRACE] UserBean:postConstruct():this.id:null
[TRACE] UserBean:viewDetailsAction():this.id:13
[TRACE] UserBean:viewDetailsAction():_return:action-view-details
[TRACE] UserBean:preDestroy():start
[TRACE] UserBean:preDestroy():this.id:13
13:47:11,454 DEBUG [DebugPhaseListener:53] AFTER phaseId=[INVOKE_APPLICATION 5] viewId=[/WEB-INF/views/result1.xhtml]
13:47:11,539 DEBUG [DebugPhaseListener:69] BEFORE phaseId=[RENDER_RESPONSE 6] viewId=[/WEB-INF/views/result1.xhtml]
[TRACE] UserBean:<init>():start
[TRACE] UserBean:<init>():this.id:null
[TRACE] UserBean:<init>():bean created
[TRACE] UserBean:postConstruct():start
[TRACE] UserBean:postConstruct():this.id:null
13:47:11,832 DEBUG [DebugPhaseListener:53] AFTER phaseId=[RENDER_RESPONSE 6] viewId=[/WEB-INF/views/result1.xhtml]
此外,URL已从http:// localhost:8080/web/guest/guest/mission
更改to http://localhost:8080/web/guest/mission?p_auth=TBepgy6o&p_p_id=testparam_WAR_testparam&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=&p_p_col_count=0&_testparam_WAR_testparam__facesViewIdRender=%2FWEB -inf%2fviews%2findex.xhtml
,这是我想避免的。
我不知道我要执行想要的方法是正确的方法。如果不是这样,我将感谢任何澄清;如果我处于正确的道路上,我将感谢任何澄清为什么要执行第二个Render_Response阶段。
背景:
- JSF 2.2,
- Liferay 7.4 Ga1
- Liferay面孔。
On a Liferay-Faces portlet, I want to navigate from a .xhtml page to another .xhtml page passing a parameter so that this second page displays the parameter passed. As I don’t want to give any clue about the parameter I’m passing, I decided to tackle that task on the basis of a POST request, so I chose to use a <h:commandLink> feature.
faces-config.xml:
<managed-bean>
<managed-bean-name>bUser</managed-bean-name>
<managed-bean-class>es.my.samples.UserBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>WEB-INF/views/index.xhtml</from-view-id>
<navigation-case>
<from-action>#{bUser.viewDetailsAction}</from-action>
<from-outcome>action-view-details</from-outcome>
<to-view-id>WEB-INF/views/result1.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
page1 (index.xhtml):
<h:form>
<h:commandLink value="commandLink" action="#{bUser.viewDetailsAction()}">
<f:param name="id" value="13" />
</h:commandLink>
</h:form>
page2 (results2.xhtml):
<h:panelGrid columns="2">
<h:outputLabel value="Requested id: " />
<h:outputText value="#{bUser.id}" />
</h:panelGrid>
Viewscoped bean (UserBean.java):
@ManagedBean(name = "bUser")
@ViewScoped
public class UserBean {
private String id;
public UserBean() {
logger.trace("bean created");
}
@PostConstruct
public void postConstruct() {
logger.trace("start");
logger.trace("this.id:" + this.id);
}
public String getId() {
return id;
}
public void setId(String id) {
logger.trace("start [id]:" + id);
this.id = id;
}
@PreDestroy
public void preDestroy() {
logger.trace("start");
logger.trace("this.id:" + this.id);
}
public String viewDetailsAction() {
String _return = "action-view-details";
Map<String,String> params =
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
this.id = params.get("id");
logger.trace("this.id:" + this.id);
return _return;
}
Being the URL set to http://localhost:8080/web/guest/mission
, when I press the ‘commandLink’ link I’m getting displayed on the screen the following error message (translated):
Cannot find the matching navigation case of the view ID '/WEB-INF/views/index.xhtml' for the action {1} with the result {2}.
If I omit on the faces-config.xml file the line <from-action>#{bUser.viewDetailsAction}</from-action>
, then the navigation is carried out, the but the page does not display the parameter passed, despite of the fact that the parameter is extracted from the JSF params
object, and as a consequence of a sort of a RENDER_RESPONSE
phase started once the action method has finished, as it can be seen on the log displayed:
[TRACE] UserBean:<init>():start
[TRACE] UserBean:<init>():this.id:null
[TRACE] UserBean:<init>():bean created
[TRACE] UserBean:postConstruct():start
[TRACE] UserBean:postConstruct():this.id:null
[TRACE] UserBean:viewDetailsAction():this.id:13
[TRACE] UserBean:viewDetailsAction():_return:action-view-details
[TRACE] UserBean:preDestroy():start
[TRACE] UserBean:preDestroy():this.id:13
13:47:11,454 DEBUG [DebugPhaseListener:53] AFTER phaseId=[INVOKE_APPLICATION 5] viewId=[/WEB-INF/views/result1.xhtml]
13:47:11,539 DEBUG [DebugPhaseListener:69] BEFORE phaseId=[RENDER_RESPONSE 6] viewId=[/WEB-INF/views/result1.xhtml]
[TRACE] UserBean:<init>():start
[TRACE] UserBean:<init>():this.id:null
[TRACE] UserBean:<init>():bean created
[TRACE] UserBean:postConstruct():start
[TRACE] UserBean:postConstruct():this.id:null
13:47:11,832 DEBUG [DebugPhaseListener:53] AFTER phaseId=[RENDER_RESPONSE 6] viewId=[/WEB-INF/views/result1.xhtml]
Moreover, the URL has changed from http://localhost:8080/web/guest/mission
to http://localhost:8080/web/guest/mission?p_auth=TBepgy6o&p_p_id=testparam_WAR_testparam&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=&p_p_col_count=0&_testparam_WAR_testparam__facesViewIdRender=%2FWEB-INF%2Fviews%2Findex.xhtml
, which is something I wanted to avoid.
I don't know if my approach to perform what I want is the right one or not. If it isn't, I’d appreciate any clarification; if I’m in the right path, I’d appreciate any clarification about why this second RENDER_RESPONSE phase is being carried out.
Background:
- JSF 2.2,
- Liferay 7.4 ga1
- Liferay Faces.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经通过使用隐式导航对其进行了整理。显式导航似乎不仅在JSF 2.X上可以使用,这是我从此 post 。在引用的帖子中,据说根本不需要
faces-config.xml
文件。但是我认为一件事是不需要的事实,而另一件事非常不同的是,强制性不必使用它的事实。就个人而言,从我的JSF1.X体验中,我曾经喜欢在
faces-config.xml
之类的配置文件中组织页面导航的方式。I've sorted it out by using implicit navigation. It seems that explicit navigation doesn't just work on JSF 2.x, which is something I conclude from this post. In the quoted post it is said that
faces-config.xml
file is not needed at all. But I think that one thing is the fact of not being needed, and another very diferent thing is the fact of being compulsory not having to use it whatsover.Personally, and from my JSF1.x experience, I used to like the way page navigation was organized in a config file like
faces-config.xml
.