[solved] [jsf-issue] problem go from jsp page to another jsp in new window

Splash Forums PrettyFaces Users [solved] [jsf-issue] problem go from jsp page to another jsp in new window

This topic contains 5 replies, has 2 voices, and was last updated by  alynoor 7 years, 2 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #17751

    alynoor
    Participant

    I’ve two jsp pages attendReport.jsp and printAttendReport.jsp

    attendReport.jsp contains inputs for attend duration and employee id and command button “view” to view attendance data entered employee during entered duration inside the same page(this work very good)

    the problem is the same page includes another command button “print” its job is to get the same data but view them in the second page printAttendReport.jsp in another window in order to print the data in some suitable format , but the print button opens attendReport.jsp instead of printAttendReport.jsp and does not hold the inputs else if I set <managed-bean-scope> to session not request which cause caching data , please help me if you to solve this problem

    and here the related lines of code

    <faces-config >

    ……

    <managed-bean>

    <managed-bean-name>attendReportBean</managed-bean-name>

    <managed-bean-class>csc.attend.bean.AttendReportBean</managed-bean-class>

    <managed-bean-scope>request</managed-bean-scope>

    </managed-bean>

    <navigation-rule>

    <from-view-id>/attend/attendReport.jsp</from-view-id>

    <navigation-case>

    <from-action>#{AttendReportBean.attendReport}</from-action>

    <from-outcome>attendReport</from-outcome>

    <to-view-id>/attend/attendReport.jsp</to-view-id>

    </navigation-case>

    </navigation-rule>

    <navigation-rule>

    <from-view-id>/attend/attendReport.jsp</from-view-id>

    <navigation-case>

    <from-action>#{AttendReportBean.printAttendReportAction}</from-action>

    <from-outcome>printAttendReportAction</from-outcome>

    <to-view-id>/attend/printAttendReport.jsp</to-view-id>

    </navigation-case>

    </navigation-rule>

    …….

    </faces-config>

    public class AttendReportBean {

    // data , getters and setters

    {

    init();

    //Preload in initialization block.

    }

    public void init() {

    // initialize data

    }

    public String attendReport() {

    // code to get attend data to go to view page(same page) it is ok

    return “attendReport”; // Navigation case.

    }

    public static String getRequestParameter(String name) {

    return (String) FacesContext.getCurrentInstance().getExternalContext()

    .getRequestParameterMap().get(name);

    }

    public void printAttendReportListener(ActionEvent event) {

    String fromYearStr = getRequestParameter(“fromYearAtt”);

    System.out.println(“fromYearStr = “+fromYearStr);

    ………………..

    // try to get inputs through ActionListener but it gives me null

    }

    public String printAttendReportAction() {

    // code to get attend data to go to print page(another page in new //window) but inputs come in default values

    return “printAttendReportAction”; // Navigation case.

    }

    }

    attendReport.jsp

    <%@ taglib uri=”http://java.sun.com/jsf/html&#8221; prefix=”h”%>

    <%@ taglib uri=”http://java.sun.com/jsf/core&#8221; prefix=”f”%>

    <f:view>

    <html xmlns=”http://www.w3.org/1999/xhtml”&gt;

    <head>

    /title . styles and validations /

    </head>

    <body>

    <h:form id=”attendReportForm”>

    /the form tag appear in running source as <form id=”attendReportForm” method=”post” action=”/newdiwan/faces/attend/attendReport.jsp” enctype=”application/x-www-form-urlencoded” >

    i.e. it always submit to attendReport.jsp page

    /

    / some inputs and outputs /

    <h:commandButton onclick=”return check();” id=”view” action=”#{attendReportBean.attendReport}” value=”” styleClass=”linksNumBlue” />

    /it works good/

    / some outputs to view data /

    <h:commandLink immediate=”true” id=”printLink” value=”” action=”#{attendReportBean.printAttendReportAction}” actionListener=”#{attendReportBean.printAttendReportListener}” target=”_blank” styleClass=”linksNumBlue”>

    /this has two problems 1)submit to attendReport.jsp not printAttendReport.jsp which I want to go to.

    2)does not get the inputs but return the default values only /

    </h:form></body></html></f:view>

    I use libraries { jsf-api.jar , jsf-impl.jar , jstl-1.1.0.jar and tomahawk-1.1.6.jar } and deploy on tomcat 6.0

    I’m sorry for the prolongation, please help me if you can

    #19986

    I’m sorry to ask this question, but what does this problem have to do with PrettyFaces? From your code it looks like you are not using PrettyFaces at all. Or am I mistaken?

    #19987

    alynoor
    Participant

    No you are write chkal i’m new to JSF and still use standard , but this problem annoys me and i hope to find someone helps me to solve it, i’ll be Grateful to him

    #19988

    Okay, here are my thoughts on your problems:

    Regarding the submit to attendReport.jsp instead of printAttendReport.jsp. I think this is correct and expected behavior. When the user clicks on the link on attendReport.jsp, JSF will perform a postback to this (the old) view. So the HTTP POST will be send to attendReport.jsp. Then you action should be called and after that printAttendReport.jsp will be rendered. Is your method printAttendReportAction() executed or not? If not, this might be caused by a validation failure on the first page. Did you include <h:messages/> on the page to verify this?

    Regarding the missing input values. This is very difficult to answer, as you didn’t include the <h:input*/> tags in the code you posted. But I think you are using a very unconventional way to access the input values (method getRequestParameter()). You should use standard Java bean properties and reference them with the value attribute of the <h:input*/> components.

    I hope this helps..

    #19989

    alynoor
    Participant

    thank you chkal for your reply

    the mehtod printAttendReportAction() is executed , i use javascript validation , adn not using <h:message> on my page

    i use standard for inputs like this

    Code:
    <h:inputText id=”civileId” value=”#{attendReportBean.civileId}” onkeypress=”return submitEnter(‘attendReportForm:view’,event)” required=”true” />

    i use method getRequestParameter() as a test to some suggestion to get parameter values

    http://balusc.blogspot.com/2006/06/communication-in-jsf.html#PassingObjectsFromRequestToRequest

    #19990

    alynoor
    Participant

    my problem solved 1- i use 2 managed bean , one of request scope (used in attendReport.jsp ) and the other with session scope (used in printAttendReport.jsp)

    2 – add new jsp contains the h:commandLink of the print (attendReportPrintAction.jsp)

    3 – divide the view of attendReport.jsp to two subviews (each subview has its own form) one contains inputs and outputs of attend and the other contains include to (attendReportPrintAction.jsp)

    <%@ include file=”attendReportPrintAction.jsp” %>

    4 – send and get parameters using two methods

    {code}

    public static Object getSessionMapValue(String key) {

    return FacesContext.getCurrentInstance().getExternalConte xt().getSessionMap().get(key);

    }

    public static void setSessionMapValue(String key, Object value) {

    FacesContext.getCurrentInstance().getExternalConte xt().getSessionMap().put(key, value);

    }

    {code}

    faces-config.xml

    {code}

    <managed-bean>

    <managed-bean-name>attendReportBean</managed-bean-name>

    <managed-bean-class>csc.attend.bean.AttendReportBean</managed-bean-class>

    <managed-bean-scope>request</managed-bean-scope>

    </managed-bean>

    <managed-bean>

    <managed-bean-name>print_attendReportBean</managed-bean-name>

    <managed-bean-class>csc.attend.bean.AttendReportBean</managed-bean-class>

    <managed-bean-scope>session</managed-bean-scope>

    </managed-bean>

    <navigation-rule>

    <display-name>viewReport</display-name>

    <from-view-id>/attend/attendReport.jsp</from-view-id>

    <navigation-case>

    <from-action>#{AttendReportBean.attendReport}</from-action>

    <from-outcome>attendReport</from-outcome>

    <to-view-id>/attend/attendReport.jsp</to-view-id>

    </navigation-case>

    </navigation-rule>

    <navigation-rule>

    <display-name>printReport</display-name>

    <from-view-id>/attend/attendReport.jsp</from-view-id>

    <navigation-case>

    <from-outcome>printAttendReportAction</from-outcome>

    <to-view-id>/attend/printAttendReport.jsp</to-view-id>

    </navigation-case>

    </navigation-rule>

    {code}

    attendReportPrintAction.jsp

    {code}

    <f:subview id=”printAttendReportSubView” >

    <h:form id=”printAttendReportForm” onsubmit=”return check222();” >

    <table width=”100%” border=”0″ cellpadding=”0″ cellspacing=”0″>

    <tr>

    <td width=”11%”>

    <table width=”70″ border=”0″ cellpadding=”0″ cellspacing=”0″>

    <tr>

    <td width=”7″ height=”28″><img src=”../images/B-left.gif” width=”7″ height=”28″ /></td>

    <td align=”center” background=”../images/B-bg.gif”>

    <h:commandLink id=”printLink” value=”طباعة” title=”طباعة” action=”#{print_attendReportBean.printAttendReport Action}” target=”_blank” styleClass=”linksNumBlue”>

    </h:commandLink>

    </td>

    <td width=”7″ height=”28″><img src=”../images/B-right.gif” width=”7″ height=”28″ /></td>

    </tr>

    </table>

    </td>

    <td align=”right”> </td>

    </tr>

    </table>

    </h:form>

    </f:subview>{code}

    i hope this helps someone

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Comments are closed.