09Q*_*534 4 jsf primefaces jsf-2
在我的JSF页面中我很少 Links{link1,link2,link3,link4}-{Student Id's}.
我尝试的是当我点击链接它打开学生信息时 "NEW WINDOW".
当我点击下一个链接时,它打开一个新窗口,但我想在同一个新窗口中打开,即目标应该是打开的同一个新窗口.
图形表示:

我在新窗口中收集STACKOVERFLOW 打开页面时试过的一段代码:
<p:dataTable id="studentDtTble" var="studData" value="#{studentController.dataList}">
<p:columnGroup type="header">
<p:row>
<p:column headerText="StudentId"></p:column>
<p:column headerText="StudentName"></p:column>
<p:column headerText="Add" ></p:column>
</p:row>
</p:columnGroup>
<p:column>
<p:commandLink id="sidlink" action="/studentinfo.xhtml" target="_blank">
<h:outputText value="#{studData.studentId}" styleClass="txtlink" />
</p:commandLink>
</p:column>
<p:column>
<h:outputText value="#{studData.studentName}" />
</p:column>
<p:column >
<p:selectBooleanCheckbox value="#{studData.add}" />
</p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)
编辑@Nosnhoj回复:When i Click on any of the SID Link then there Details Should Opened in the "Same NEW Window".
Use <h:commandLink> instead of <p:commandLink>.
I tried your code and make a little change like this:
<h:commandLink id="sidlink" action="#{studentController.selectStudent(studData)}" target="_blank">
<h:outputText value="#{studData.studentId}" styleClass="txtlink" />
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
I changed <p:commandLink> to <h:commandLink>, and call a method in the backing bean to set the selected Student.(For the New Window should need the student information.)
Here is the code of studentController.selectStudent :
private Student selectedStu;
public String selectStudent(Student stu) {
selectedStu = stu;
return "/studentinfo.xhtml";
}
Run Code Online (Sandbox Code Playgroud)
And the following is the code of New Window?
<h:form>
<h:commandLink value="Another Link" action="/anotherinfo.xhtml" target="_self"/>
<br/>
Student: <h:outputText value="#{studentController.selectedStu.studentName}"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)
Which is just showing name of the selected Student, and another link you want.
Note that the target attribute is _self because you want the new page show in the same window.
Finally, the anotherinfo.xhtml is just an empty page I created via NetBeans, so there's no need to post it.
And here's what you may see:
After clicking the id of "Johnson" :
After clicking "Another Link" :

As @User2561626 explain what he/she intended to, I update my answer as follow:
If you want a New Window pop up in stead of New Tab, you should change the code like:
<p:commandLink id="sidlink" actionListener="#{studentController.selectStudent(studData)}" oncomplete="window.open('studentinfo.xhtml', 'newwindow', 'width=300, height=250');">
<h:outputText value="#{studData.studentId}" styleClass="txtlink" />
</p:commandLink>
Run Code Online (Sandbox Code Playgroud)
I change <h:commandLink> back to <p:commandLink>, make action as actionListener because we want to set the selected Student first, finally I add window.open in oncomplete attribute so that the new page will open in a new window but not tab.
Of course we need to edit the method studentController.selectStudent(), like this:
public void selectStudent(Student stu) {
selectedStu = stu;
}
Run Code Online (Sandbox Code Playgroud)
As you can see, the return type is void now, and the only thing this method do is just set the selected Student.
Hope this may help.
| 归档时间: |
|
| 查看次数: |
14174 次 |
| 最近记录: |