• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Not able to call method from action class from jsp page in Struts 1.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Please help me out. Here I am implementing delete functionality in demo example.
I have implemented all business layer and data layer methods with tests, those are correct.
I stuck into presentation layer not able to call method from action class from jsp page.
I have done struts configuration for action classes.
I am attaching here my code.

Please help Thanks in advance

Deepali Katkar

DemoA.jsp

<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/tld/struts-tiles.tld" prefix="tiles"%>
<%@ taglib uri="/WEB-INF/tld/struts-nested.tld" prefix="nested"%>
<%@ taglib uri="/WEB-INF/tld/impact-html.tld" prefix="html"%>
<%@ taglib prefix="widgets" tagdir="/WEB-INF/tags"%>
<%@ taglib uri="/WEB-INF/tld/impact-tab.tld" prefix="tab"%>
<%@ taglib uri="/WEB-INF/tld/impact-buttons.tld" prefix="button"%>
<%@ taglib uri="/WEB-INF/tld/impact-layout.tld" prefix="layout"%>
<%@ taglib uri="/WEB-INF/tld/impact-formatter.tld" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/impact-security.tld" prefix="security"%>
<%@ taglib uri="/WEB-INF/tld/i3-web.tld" prefix="i3web"%>

<html:errors simulateClientSide="true" bundle="demo" />

<html:form action="DemoADeleteAction.do" metaDataEntityName="demoADetails">

<input type="hidden" id="dispatch" name="dispatch" value="delete">
<!-- <input type="hidden" id="dispatch" name="dispatch" value="delete"> -->
<html:hidden property="demoAId" />

<tab:tabrow>
<tab:link bundle="demo" labelKey="tab.demoA.list"
action="/DemoAListAction.do?dispatch=list" selected="false"
toSession="false" />
<tab:link bundle="demo" labelKey="tab.demoA.edit"
action="/DemoAAction.do?dispatch=edit" selected="true" />
</tab:tabrow>
<c:if test="${!(empty planId)}">
<widgets:pageContext refType="PlanInfo" refId="${planId}" />
</c:if>
<br>
<div class="scrollingTabBody">
<table class="impact3form2column">
<tr>
<th>
<fmt:message bundle="demo" metaDataRef="demoType" />
</th>
<td>
<html:text property="demoType" styleClass="large" />
</td>
</tr>
<tr>
<th>
<fmt:message bundle="demo" metaDataRef="demoName" />
</th>
<td>
<html:text property="demoName" styleClass="large" />
</td>
</tr>
<tr>
<th>
<fmt:message bundle="demo" metaDataRef="demoDate" />
</th>
<td>
<html:date property="demoDate" maxlength="10" size="11"
id="demoDate"></html:date>
</td>
</tr>
<tr>
<th>
<fmt:message bundle="demo" metaDataRef="demoTimestamp" />
</th>
<td>
<html:dateTime property="demoTimestamp" maxlength="10" size="11"
id="demoDateTime"></html:dateTime>
</td>
</tr>
<tr>
<th valign="top">
<fmt:message bundle="demo" metaDataRef="demoTimezone" />
</th>
<td>
<html:select property="demoTimezone" styleClass="short">
<option value="">
<bean:message key="option.pleaseSelect" />
</option>
<html:options lookupName="TimezoneCode" labelProperty="abbr"
property="code" />
</html:select>
</td>
</tr>
<tr>
<th>
<fmt:message bundle="demo" metaDataRef="demoAmount" />
</th>
<td>
<html:currency property="demoAmount" leaveBlankStrings="true" />
</td>
</tr>
<tr>
<th>
<fmt:message bundle="demo" metaDataRef="demoIndicator" />
</th>
<td>
<html:checkbox property="demoIndicator" value="true"></html:checkbox>
</td>
</tr>
<tr>
<th>
<fmt:message bundle="demo" metaDataRef="comments" />
</th>
<td>
<html:textarea property="comments" rows="4" cols="60"></html:textarea>
</td>
</tr>
<tr>
<th>
<fmt:message bundle="demo" metaDataRef="activeIndicator" />
</th>
<td>
<html:checkbox property="activeIndicator" value="true"></html:checkbox>
</td>
</tr>
</table>
</div>

<div class="formButtons">
<!-- <button:save onclick="DemoASaveAction.do?dispatch=save" value="save"/> -->
<button:delete onclick="DemoADeleteAction.do?dispatch=delete" value="delete" />
<button:reset />
</div>

</html:form>
 
Deepali Katkar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Action class

package com.ibm.ptp.i3.web.demo;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ptp.common.utils.DateUtil;
import com.ptp.impact.common.web.components.menu.SelectedMenuNode;
import com.ptp.impact.common.web.struts.BaseDispatchAction;
import com.ptp.impact.common.web.validator.CustomLazyValidatorForm;

import com.ibm.ptp.i3.common.user.security.ImpactUser;
import com.ibm.ptp.i3.demo.assembler.DemoAPageDTO;
import com.ibm.ptp.i3.demo.assembler.IDemoAAssembler;
import com.ibm.ptp.i3.domain.exception.ImpactValidationException;
import com.ibm.ptp.i3.events.EventFactory;
import com.ibm.ptp.i3.events.manager.IEventService;
import com.ibm.ptp.i3.events.model.Event;
import com.ibm.ptp.i3.events.model.EventFlushMode;
import com.ibm.ptp.i3.transaction.TransactionEventTypeEnum;
import com.ibm.ptp.i3.transaction.model.ReferenceContextData;
import com.ibm.ptp.i3.transaction.model.TransactionInfo;
import com.ibm.ptp.i3.transaction.service.ITransactionReferenceDataService;
import com.ibm.ptp.i3.web.SessionUtil;
import com.ibm.ptp.i3.web.SessionVariables;

/**
* //TODO <Replace with Purpose>.
*
* @author deepali_katkar
* @since Dec 31, 2012
*/
public class DemoAAction extends BaseDispatchAction {

private static final Logger logger = Logger.getLogger(DemoAAction.class);

private ITransactionReferenceDataService transRefDataService;
private IEventService eventService;
private IDemoAAssembler demoAAssembler;

public ActionForward list(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.info("DemoAAction.list");

CustomLazyValidatorForm lazyForm = (CustomLazyValidatorForm) actionForm;
List<DemoAPageDTO> demoAPageDtoList = demoAAssembler.listAllDemoA();

lazyForm.set("demoAList", demoAPageDtoList);

return mapping.findForward("list");
}

public ActionForward edit(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.info("DemoAAction.edit");

CustomLazyValidatorForm lazyForm = (CustomLazyValidatorForm) actionForm;
String strDemoAId = getFieldOrParameter("demoAId", lazyForm, request);
Long demoAId = StringUtils.isNotBlank(strDemoAId)?Long.valueOf(strDemoAId):null;
DemoAPageDTO pageDto = null;

if(demoAId != null){
pageDto = demoAAssembler.getDemoADTO(demoAId);
copyDtoToLazyForm(pageDto, lazyForm, true);

if (pageDto.getDemoTimestamp() != null) {
lazyForm.set("demoTimestamp", DateUtil.formatAsRFC3339(pageDto.getDemoTimestamp()));
}

}

return mapping.findForward("edit");
}

public ActionForward save(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.info("DemoAAction.save");

CustomLazyValidatorForm lazyForm = (CustomLazyValidatorForm) actionForm;
DemoAPageDTO pageDto = new DemoAPageDTO();
copyLazyFormToDto(lazyForm, pageDto, true);

if (StringUtils.isBlank((String) lazyForm.get("demoTimestamp_dateTime")) && StringUtils.isBlank((String) lazyForm.get("demoTimestamp"))) {
pageDto.setDemoTimestamp(null);
} else if (StringUtils.isBlank((String) lazyForm.get("demoTimestamp_dateTime")) && StringUtils.isNotBlank((String) lazyForm.get("demoTimestamp"))) {
pageDto.setDemoTimestamp(DateUtils.parseDate((String) lazyForm.get("demoTimestamp"), new String[] { DateFormatUtils.ISO_DATE_FORMAT
.getPattern() }));
} else {
pageDto.setDemoTimestamp(DateUtil.getDateFromRfc3339((String) lazyForm.get("demoTimestamp")));
}

try
{
pageDto = demoAAssembler.saveDemoADTO(pageDto);
}
catch( ImpactValidationException v )
{
ActionErrors errors = new ActionErrors();
addDomainValidationErrors(errors, v);
addErrors(request, errors);
copyDtoToLazyForm(pageDto, lazyForm, true);
return getValidationErrorForward(mapping, request);
}

ActionForward forward = mapping.findForward("success");

return forward;
}
public ActionForward delete(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("******************Inside delete");
logger.info("DemoAAction.delete");

CustomLazyValidatorForm lazyForm = (CustomLazyValidatorForm) actionForm;
DemoAPageDTO pageDto = new DemoAPageDTO();
copyLazyFormToDto(lazyForm, pageDto, true);

if (StringUtils.isBlank((String) lazyForm.get("demoTimestamp_dateTime")) && StringUtils.isBlank((String) lazyForm.get("demoTimestamp"))) {
pageDto.setDemoTimestamp(null);
} else if (StringUtils.isBlank((String) lazyForm.get("demoTimestamp_dateTime")) && StringUtils.isNotBlank((String) lazyForm.get("demoTimestamp"))) {
pageDto.setDemoTimestamp(DateUtils.parseDate((String) lazyForm.get("demoTimestamp"), new String[] { DateFormatUtils.ISO_DATE_FORMAT
.getPattern() }));
} else {
pageDto.setDemoTimestamp(DateUtil.getDateFromRfc3339((String) lazyForm.get("demoTimestamp")));
}

try
{
pageDto = demoAAssembler.deleteDemoADTO(pageDto);
}
catch( ImpactValidationException v )
{
ActionErrors errors = new ActionErrors();
addDomainValidationErrors(errors, v);
addErrors(request, errors);
copyDtoToLazyForm(pageDto, lazyForm, true);
return getValidationErrorForward(mapping, request);
}

ActionForward forward = mapping.findForward("success");

return forward;
}
public ActionForward editByRefType(ActionMapping mapping, ActionForm actionForm,HttpServletRequest request, HttpServletResponse response) throws Exception{
logger.info("DemoAAction.editByRefType");

CustomLazyValidatorForm lazyForm = (CustomLazyValidatorForm) actionForm;

String refType = getFieldOrParameter("refType", lazyForm, request);
String refId = getFieldOrParameter("refId", lazyForm, request);



if(refType==null || StringUtils.isBlank(refType))
throw new RuntimeException("Required field refType is null or Blank");
else if(refId==null || StringUtils.isBlank(refId))
throw new RuntimeException("Required field refId is null or Blank");


ReferenceContextData referenceContextData = transRefDataService.getReferenceContext(refType, new Long(refId));

if(referenceContextData==null)
throw new RuntimeException("Reference Context Data was not created");


ImpactUser.getImpactUserFromThread().switchCompanyOrganization(referenceContextData.getDefaultCompanyOrgId());
String transId = (String) SessionUtil.get(request, SessionVariables.transactionId);

if (transId == null || !referenceContextData.getDefaultTransactionId().toString().equals(transId)) {
publishLoanOpened(referenceContextData);
SessionUtil.setSessionData(referenceContextData, request);
}

SelectedMenuNode mn = new SelectedMenuNode("demo", "sitemap");
request.setAttribute(mn.getClass().getSimpleName(), mn);


ActionForward forward = edit(mapping, actionForm, request, response);
return forward;

}

private void publishLoanOpened(ReferenceContextData referenceContextData) {
Event event = EventFactory.createEvent(referenceContextData.getDefaultCompanyOrgId(), referenceContextData.getDefaultLobId(), TransactionEventTypeEnum.LoanOpenedEvent);
event.setEventFlushMode(EventFlushMode.Immediate);
event.setRefId(referenceContextData.getDefaultTransactionId());
event.setRefType(TransactionInfo.DATA_REF_TYPE);
eventService.publish(event);
}

public void setTransRefDataService(ITransactionReferenceDataService transRefDataService) {
this.transRefDataService = transRefDataService;
}

public void setEventService(IEventService eventService) {
this.eventService = eventService;
}

public void setDemoAAssembler(IDemoAAssembler demoAAssembler) {
this.demoAAssembler = demoAAssembler;
}

}


strutsBean-demo.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">;
<!-- define the spring-aware action classes here. The bean name -->
<!-- *must* be exactly the same as the action path name -->
<!-- this file can be split into multiple files by changing the file names
in web.xml -->
<bean name="/DemoAListAction"
class="com.ibm.ptp.i3.web.demo.DemoAAction">
<property name="demoAAssembler" ref="transaction.demoAssembler" />
<property name="transRefDataService"
ref="transaction.transactionReferenceDataService" />
<property name="eventService" ref="events.eventService" />
</bean>

<bean name="/DemoAAction" parent="/DemoAListAction" />

<bean name="/DemoASaveAction"
class="com.ibm.ptp.i3.web.demo.DemoAAction">
<property name="demoAAssembler" ref="transaction.demoAssembler" />
<property name="transRefDataService"
ref="transaction.transactionReferenceDataService" />
<property name="eventService" ref="events.eventService" />
</bean>

<bean name="/DemoADeleteAction"
class="com.ibm.ptp.i3.web.demo.DemoAAction">
<property name="demoAAssembler" ref="transaction.demoAssembler" />
<property name="transRefDataService"
ref="transaction.transactionReferenceDataService" />
<property name="eventService" ref="events.eventService" />
</bean>
</beans>

struts-demo.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">;
<struts-config>

<form-beans>
<form-bean name="lazyForm"
type="com.ptp.impact.common.web.validator.CustomLazyValidatorForm">
</form-bean>
</form-beans>

<global-forwards>

</global-forwards>

<action-mappings>

<!-- Demo A Actions -->
<action path="/DemoAListAction"
type="org.springframework.web.struts.DelegatingActionProxy"
name="lazyForm" attribute="lazyForm" parameter="dispatch"
input=".demo.list" validate="false" scope="request">
<set-property key="PAGE_CODE" value="demoAList" />
<forward name="list" path=".demo.list" />
</action>

<action path="/DemoAAction"
type="org.springframework.web.struts.DelegatingActionProxy"
name="lazyForm" attribute="lazyForm" parameter="dispatch"
input=".demo.edit" validate="false" scope="request">
<set-property key="PAGE_CODE" value="demoA" />
<forward name="edit" path=".demo.edit" />
<forward name="success"
path="/DemoAListAction.do?dispatch=list" redirect="true" />
</action>

<action path="/DemoASaveAction"
type="org.springframework.web.struts.DelegatingActionProxy"
name="lazyForm" attribute="lazyForm" parameter="dispatch"
input=".demo.edit" validate="true" scope="request">
<set-property key="PAGE_CODE" value="demoA" />
<forward name="edit" path=".demo.edit" />
<forward name="success"
path="/DemoAListAction.do?dispatch=list" redirect="true" />
</action>

<action path="/DemoADeleteAction"
type="org.springframework.web.struts.DelegatingActionProxy"
name="lazyForm" attribute="lazyForm" parameter="dispatch"
input=".demo.edit" validate="true" scope="request">
<set-property key="PAGE_CODE" value="demoA" />
<forward name="edit" path=".demo.edit" />
<forward name="success"
path="/DemoAListAction.do?dispatch=list" redirect="true" />
</action>

</action-mappings>

<message-resources key="demo"
parameter="com.ibm.ptp.i3.web.demo.DemoResources" />

</struts-config>
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please provide the log/error details
 
Deepali Katkar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

arkaes Duraimoni wrote:Could you please provide the log/error details



Hi,
I am sorry for late response. Problem here is I am not getting any error or exception on consol so I am not able to figure it out

Thank you,
Deepali Katkar
 
Deepali Katkar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
Its resolved.
I have just added java script function which gets called after clicking on delete. In taht function I wrote form.submit();

Now it's working fine.

Thanks,
Deepali Katkar
 
So I left, I came home, and I ate some pie. And then I read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic