我有一个用例,我有一个使用dataTable显示的用户列表。
我已针对每条记录生成了编辑和查看链接。
我想要做的是,只要点击查看链接,就应该有一个单独的页面,其中包含用户的详细信息。
<h:commandLink action="#{profile.goToViewPage(profileVar.profileId)}" value="view" />
因此值正确传递给Bean。
@Named("profile")
@Scope("view")
public class ProfileDTO {
private String firstName;
private String lastName;
private Date dob;
//Getters and Setters
private void getUser(String selectedProfile) {
this.setDob(new Date());
this.setFirstName("Tested from Page First");
this.setLastName("Test from Page Last");
}
public String goToViewPage(String selectedProfile) {
LOG.debug("Goto View Page called for user id : {}", selectedProfile);
getUser(selectedProfile);
return "pretty:viewprofile"; //Using prettyfaces
}
}
viewPage xhtml类似于:
<rich:collapsiblePanel header="Basic Details" switchType="client" expanded="true">
<h:panelGroup styleClass="align-table-center-horizontal" layout='block'>
<h:column>
<h:panelGrid columns="2" style="width:100%;" columnClasses="right-column half-width,left-column half-width">
<h:column>
<h:outputText styleClass="headerText" value="First Name" />
</h:column>
<h:column>
<h:inputText value="#{profile.firstName}" />
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="Last Name" />
</h:column>
<h:column>
<h:inputText value="#{profile.lastName}" />
</h:column>
</h:panelGrid>
</h:column>
</h:panelGroup>
</rich:collapsiblePanel>
我用来显示列表的bean在会话范围内。
问题: 方法获取调用“goToViewPage”并设置虚拟数据,但稍后再次调用构造函数并丢失所有数据。
答案 0 :(得分:0)
好的,我发现了这个问题。它不是jsf和更多漂亮的脸。问题已解决,使用查询参数并重新构建对象以供显示。
<url-mapping id="viewprofile">
<pattern value="/a" />
<view-id value="/a/b.jsf" />
<query-param name="id">#{bean.id}</query-param>
<action>#{bean.loadViewPageData}</action>
</url-mapping>
使用pretty-faces配置时,将设置action方法,该方法将在重定向请求后调用。