how to change target of Struts2 jquery plugin dynamically - struts2

I have reportCriteria.jsp as follows:
<s:form action="showPdf" theme="css_xhtml" cssClass="form1small" name="reportgenerationform">
<div id="searchHeaderReport">Generate Report</div>
<div id="searchForm1">
<s:select list="#application.proList" headerValue="Select" headerKey="select" label="Provider" id="providerId" name="providerName"></s:select>
<div id="wwgrp_flightId" class="wwgrp">
<div id="wwerr_showPdf_flightId" class="wwerr">
<div class="errorMessage">
</div>
</div>
<div id="wwlbl_flightId" class="wwlbl">
<label class="label" for="flightId"> Flight ID: </label>
</div>
<div id="wwctrl_flightId" class="wwctrl">
<select id="flightId" name="flightId">
<option selected="selected">select</option>
</select>
</div>
</div>
<div id="wwgrp_scheduleId" class="wwgrp">
<div id="wwerr_showPdf_flightId" class="wwerr">
<div class="errorMessage">
</div>
</div>
<div id="wwlbl_flightId" class="wwlbl">
<label class="label" for="scheduleId"> Schedule ID: </label>
</div>
<div id="wwctrl_flightId" class="wwctrl">
<select id="scheduleId" name="scheduleId">
<option selected="selected">select</option>
</select>
</div>
</div>
</div>
<div id="submitdivid">
<sj:submit value="Generate Report" cssClass="orangebuttonsmall"/>
</div>
</s:form>
The struts.xml mapping is as follows:
<action name="showPdf" class="com.view.ReportAction" method="showReport">
<result name="report" type="stream">
<param name="inputName">fileStream</param>
<param name="contentType">application/pdf</param>
<param name="contentDisposition">attachment;filename="PDF_Report.pdf"</param>
</result>
<result name="input">/reportCriteria.jsp</result>
</action>
<action name="flightMgmt" class="com.view.AdminAction" method="flightMgmt">
<result name="flightMgmtClicked">/flightMgmt.jsp</result>
</action>
<action name="reportGeneration" class="com.view.AdminAction" method="reportGeneration">
<result name="reportGenerationClicked">/reportCriteria.jsp</result>
</action>
Now if the method showReport returns "report", then the pdf content is loaded in encrypted form in div with id as "report_generation".
When the method returns input, then it loads reportCriteria.jsp with errors in the div with id as "report_generation".
What i want to do is that when it returns error then the jsp must be loaded into that div but if the method returns "report" which it returns on success, then the file download box must appear as shown in result type="report" in struts.xml.
The following is "loginSuccessAdmin.jsp" that contains "report_generation" div :*
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<s:url var="remoteurl1" action="flightMgmt"/>
<s:url var="remoteurl2" action="reportGeneration"/>
<s:url var="remoteurl3" action="dealMgmt"/>
<sj:tabbedpanel id="remotetabs" selectedTab="0" collapsible="true">
<sj:tab id="tab1" href="%{remoteurl1}" label="Flight Management"/>
<sj:tab id="tab2" href="%{remoteurl2}" label="Report Generation"/>
<sj:tab id="tab3" href="%{remoteurl3}" label="Deal Management"/>
</sj:tabbedpanel>
</div>
The line <sj:tab id="tab2"> itself creates a div with id as report_generation.
Is there anything possible, that may accomplish my purpose..
Thanks in advance

That's not possible.
Javascript can't download files to a user's computer unless you code some workaround. Like this guy here.
Don't use the same action for fileDownload and error, instead split in two with the first one telling whether the fileDownload will work and then accordingly you can call the second one with sureity of receiving a file or it can show you the errors which you can push in a div like you're doing now.

Related

Datepicker not working on react router childs (until refresh)

I am facing a issue with the react router, where the child router has a component form with datepicker(semantic-ui-calender) and a default dropdown from semantic-ui.
Issue is : By entering to the child route these styles are not working, shows only default select option for dropdown and datepicker was just a input now. If i refresh the page those are working.
Here is the router section
<Route path="/examination" component={Examination}>
<IndexRoute component={Add_new_schedule}/>
<Route path="/examination/AddNewSchedule" component={Add_new_schedule} />
<Route path="/examination/AddExam" component={Add_exam} />
</Route>
Here is the Dropdown
<div className="exam_class_section">
<select className="ui dropdown">
<option value>Section</option>
<option value="A">A</option>
<option value="B">B</option>
</select>
</div>
Here is the Datepicker (Semantic-UI-Calender) with date, time-from, time-to
<div className="exam_date_time_box">
<div id="exam_date" className="ui calendar">
<div className="ui left icon input">
<input
type="text"
placeholder="Examination Date" />
<i className="calendar icon" />
</div>
</div>
<div className="exam_time_box">
<div id="time_from" className="ui calendar">
<div className="ui input left icon">
<i className="time icon" />
<input type="text" placeholder="Time From" />
</div>
</div>
<div id="time_to" className="ui calendar">
<div className="ui input left icon">
<i className="time icon" />
<input type="text" placeholder="Time To" />
</div>
</div>
</div>
</div>
Thanks
I got solution for this problem.
The issue is because external js files will not load in react-router.
The Solution is load the external js file with loadjs library by importing into the specific component page where it is required
import loadjs from 'loadjs' and call inside componentWillMound() lifecycle method
componentWillMount() {
loadjs('/js/main.js');
},

Unable to get values in JSP in Struts2 Liferay6.2 Portlet

Brief Overview: I am trying to port a webapp based on Struts2 ,into a Struts2 Liferay portlet.
Problem definition: The values are fetched as NULL/Blank even if if the action Class method is setting the values properly in my variables.
I have tried printing out the values when my method is returned in Action Class and also in my jsp. The values are getting properly set as I can see it from the loggers put in place just before returning SUCCESS, but in the jsp I can see all the required set variables are blank!!
Code snippet:
In jsp the code is fetching the values as below:
For instance
<br>
<s:if test="%{xyz!= null}">
<br />
<div style="margin-left:9em;">
<s:property value="xyz" escapeHtml="false"/> //never displayed as xyz is NULL
</div>
<br /><br />
</s:if>
<br>
on printing out xyz: <s:text name="%{xyz}"/> , I get blank values , this happens for all the required values in the jsp.
The options I have tried out:
I have tried using : %{#xyz}, %{xyz}, but didn't helped.
struts.xml
<action name="selectSite" class="com.abc.xyz.LandingPageAction"
method="selectSite">
<interceptor-ref name="abAjaxCallInterceptorStack" />
<result name="success" >/WEB-INF/jsp/portal/LandingContent.jsp</result>
</action>
liferay-portlet.xml:
<liferay-portlet-app>
<portlet>
<portlet-name>xyz-portlet</portlet-name>
<icon>/icon.png</icon>
<private-session-attributes>false</private-session-attributes>
<requires-namespaced-parameters>false</requires-namespaced-parameters>
<header-portlet-css>/css/main.css</header-portlet-css>
<footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
<add-default-resource>true</add-default-resource>
</portlet>
</liferay-portlet-app>
jsp page:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<br>
<s:if test="%{xyz!= null}">
<br />
<div style="margin-left:9em;">
<s:property value="xyz" escapeHtml="false"/>
</div>
<br /><br />
</s:if>
<br>
<br />
<sj:tabbedpanel id="billTab" >
<sj:tab id="overview" href="%{overviewURL}" label="Overview"
target="overviewDiv" indicator="loadingInd" />
<sj:tab id="invoices" href="%{invoiceURL}" label="Invoices"
target="invoicesDiv" indicator="loadingInd" />
<div id="overviewDiv" ></div>
<div id="invoicesDiv" ></div>
</sj:tabbedpanel>
try
<s:if test="xyz!= null">
if xyz is on the valuestack then you don't need to use %
You can also use Set tag to expose these values such as
<s:set var="varName" value="xyz"/>then just refer to it as varName instead of #varName
If you are accessing vars in a different portlet you will have set the value for the variable as at least request scope like this
<s:set var="varName" value="xyz" scope="request"/>
Then you can access them like this from another portlet in the same page
<s:if test="#request.xyz != null">

Primefaces reset messages in p:dialog

I am opening a popup on click of command link, and popup has a textbox and commandLink
whenever I press submit with textbox left blank, it shows validation msg, till now this is fine. Now if I close the popup using cross icon on top right. then again click to showPopup, it show the error messages . I want to clear that messages and open fresh popup.
below is my code
<p:commandLink id="showDialogButton" styleClass="add_icon"
value="ADD" onstart="#{dashboardBean.resetFoodPromoDTO()}" oncomplete="PF('dlg').show()" />
bean
public void resetFoodPromoDTO(){
foodPromoDTO=null;
}
popup dialog
<p:dialog id="dialog" visible="#{not empty facesContext.messageList}" styleClass="customized" widgetVar="dlg" draggable="true" closable="true" resizable="false" width="730">
<div class="popup_subheader">
<div class="float_left">Add - Food Promotion Activity</div>
<div class="float_right"></div>
<div class="clear"></div>
</div>
<div class="popuptext">
<div class="form-label"><label title="Project">Project: </label></div>
<div class="form-field"><p:inputText id="projectName" value="#{dashboardBean.foodPromoDTO.project}" required="true" requiredMessage="#{msg['validation.project.name']}"/>
<p:message id="projeMsgId" for="projectName" autoUpdate="true"/>
</div>
<div class="clear"> </div>
<div class="form-label"><label title="Promo Date">Promo Date:</label></div>
<div class="btn_area_popup">
<span>
<p:commandLink id="submitButton" validateClient="true" value="Save" action="#{dashboardBean.addFoodPromotion()}" update="#form" onuccess="PF('dlg').hide();" ajax="true"/>
</span>
</div>
<div class="clear"></div>
You have to update the dialog
<p:dialog id="dialog" visible="#{not empty facesContext.messageList}" styleClass="customized" widgetVar="dlg" draggable="true" closable="true" resizable="false" width="730">
<h:form id="dialog">
<p:panel id="dialogBody">
....
</p:panel>
</h:form>
</p:dialog>
You can update dialog with this code:
<p:commandLink id="showDialogButton" styleClass="add_icon"
value="ADD" actionListener="#{dashboardBean.resetFoodPromoDTO()}" oncomplete="PF('dlg').show()" update=":dialog:dialogBody" />
You have to use actionListener.

how to implement struts2 action error in the jquery grid page

i have a jsp page with struts2 jquery grid. I want to show errors in the jsp page from my action class.
To show error i am adding error messsage using
addActionError("You can not delete this data");
code in my action class. And to display it i am using
<s:if test="hasActionErrors()">
<div class="errors">
<s:actionerror/>
</div>
</s:if>
code in my jsp page. But unfortunately ,I am unable to show error in my jsp page.
Please share your knowladge regarding this issue.
-Thank you
Ashutosh
Full Code:
index.jsp:
.....
.....
<body>
<s:if test="hasActionErrors()">
<div class="errors">
<s:actionerror/>
</div>
</s:if>
<div id="setpage"> <s:url id="editurl" action="nedit"/>
<s:url id="editurl" action="nedit"/>
<s:url id="remoteurl" action="ntable"/>
<sjg:grid
id="gridtable"
caption="List of Subject Details"
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="gridModel"
rowList="50,100,5000"
rowNum="20"
.....
......
My action.java
.........
.........
else
{
addActionMessage("Unable to delete row");
return ERROR;
}
return SUCCESS;
.........
.........
struts.xml
<package name="gridedition" extends="struts-default,json-default">
<action name="editionntableshow" class="v.esoft.actions.actionfile" >
<result name="success" type="json"/>
<result name="error" type="json"/>
</action>
<action name="editionedit" class="v.esoft.actions.editiondetails.EditiondetailsEditAction">
<result name="success" type="json"></result>
</action>
</package>
This solved my problem...
<s:if test="hasActionErrors()">
<div class="errors">
<s:actionerror theme="jquery"/>
</div>
</s:if>
jqGrid submit the delete row action by ajax, while those hasActionErrors are not ajax operations so they cannot be caught.
In order to catch these action error/messages, that should not be a ajax/json action.

Primefaces printer print div

I want to print one div with primefaces printer (primefaces 3.2 with myfaces 2.0).
My faces code is like:
<div id="page">
<!-- SIDEBAR -->
<div id="sidebar"
class="ui-widget-content ui-corner-all ui-helper-clearfix ui-shadow sidebar">
<ui:insert name="sidebar"></ui:insert>
<p:commandButton value="Print" type="button">
<p:printer target="content" />
</p:commandButton>
</div>
<!-- CONTENT -->
<div id="content">
<ui:insert name="content">...</ui:insert>
</div>
<div style="clear: both;"> </div>
</div>
But I get a FacesException:
javax.faces.FacesException: Cannot find component content in view.
Is this possible with primefaces printer or is there another way to do this.
Best Regards Veote
p:printer expects an id of the component, but ui:insert defines a logical section which is going to be inserted by the client. You could try to wrap the content you wish to print in p:outputPanel like so:
<p:outputPanel id="content">
<ui:insert name="content" />
</p:outputPanel>

Resources