4

In my JSF page i have few Links{link1,link2,link3,link4}-{Student Id's}.

What i tried is when i click on the Link it Opens the Student-Information in a "NEW WINDOW".

When i am clicking on the next Link it is Opening a New Window,but i want to open in the Same New Window i.e., the TARGET should be the Same NEW Window which is opened.

Diagramatical Representation:

Target Link to Same Window

My Piece of Code which i had tried from collecting things from STACKOVERFLOWOpen Page in New Window :

<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>

Edited After @Nosnhoj Reply :When i Click on any of the SID Link then there Details Should Opened in the "Same NEW Window".

Community
  • 1
  • 1
09Q71AO534
  • 4,300
  • 13
  • 44
  • 68
  • @Makky i had pasted a sample code hope it may help.As, i am new to JSF, Primefaces.i'm unable to make it up. correct me if i am going wrong any where. Thanks for the reply – 09Q71AO534 Jan 01 '14 at 18:34
  • Did you try the answers in your previous questions? – Makky Jan 01 '14 at 18:46
  • Can you not use Dialog box instead of showing results in different tab ?? – Makky Jan 01 '14 at 18:50
  • @Makky My Reqirement is that i have a Page of Student Information to be Displayed, So i want to Show them as a Separate Page. The Dialog Box is a good One which can be useful, but it is'nt the case i want to be..i added a comment for the answer Below – 09Q71AO534 Jan 02 '14 at 05:45

1 Answers1

5

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>

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";
}

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>

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:
enter image description here

After clicking the id of "Johnson" :
enter image description here

After clicking "Another Link" :
enter image description here


Update

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>

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;
}

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.

nosnhoj
  • 793
  • 1
  • 12
  • 30
  • The answer is good! It is working Fine. but, my requirement is that if we click on the sid Consider in your scenario u had clicked on sid:2 and then the "NEW WINDOW" had opened.then again if i click on sid:4 then the same "NEW WINDOW" should be Refreshed and display the StudentInfo. – 09Q71AO534 Jan 02 '14 at 05:43
  • Then just change `target="_blank"` to `target="_new"`. – nosnhoj Jan 02 '14 at 05:53
  • how can it open in the Same window which is opened, then for every link i click it opens a NEW Window, there the old Window Remains Opened. – 09Q71AO534 Jan 02 '14 at 05:59
  • The `target="_new"` is working fine.but, i am surprised how can it open in the same Window.. It is opening a Window as a new "tab", can we make it open in a "New Window" – 09Q71AO534 Jan 02 '14 at 06:11
  • It Worked fine! but As on the Second Click it is not Focusing on the New Window. i tried with `window.open('studentinfo.xhtml', 'newwindow', 'width=300, height=250').focus();` it worked ! Thanks For your Support – 09Q71AO534 Jan 02 '14 at 15:00