Binding actionsBeans correctly

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Binding actionsBeans correctly

Nahid Seidi
In following code I am calling a method in 'FirstAction' from 'SecondAction'. 

When exception occurs in 'FirstAction' I need the 'getSourcePageResolution' to get back to 'import.jsp' as the UrlBinding is saying so, but instead, it gets back to a default error page which I defined in web.xml as following:

<error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/jsp/error.jsp</location>
</error-page>

Here is the code for two actions and one jsp that I'm using

FirstAction.java

@UrlBinding("/example/import.action")
public class FirstAction implements ActionBean {
@DontValidate
public Resolution importTable() throws IOException  {
try {
// do something
} catch(Exception e) {
this.getContext().getValidationErrors().addGlobalError(new SimpleError(e.getMessage()));
return getContext().getSourcePageResolution();
}
return new RedirectResolution("/list.action");
}
}

SecondAction.java

public class SecondAction implements ActionBean {
@DefaultHandler
@DontValidate
public Resolution callImportTable() {
return new RedirectResolution (FirstAction.class, "importTable");
}
}

import.jsp

<stripes:link beanclass="com.example.action.SecondAction" event="callImportTable">
<input type="button" value="Import table" />
</stripes:link>

Is there any way to do the binding from 'SecondAction' to 'FirstAction' so  'getSourcePageResolution' shows the 'import.jsp' instead of 'error.jsp' ?

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Binding actionsBeans correctly

Rick Grashel
Nahid,

Again, I can't see all the code you are using, but it looks like you can just have SecondAction extend FirstAction:

public class SecondAction extends FirstAction {
@DefaultHandler
@DontValidate
public Resolution callImportTable() {
return super.importTable();
}
} 

I can't see all the code you have, so this may or may not work.

-- Rick


On Fri, Feb 27, 2015 at 7:41 AM, Nahid Seidi <[hidden email]> wrote:
In following code I am calling a method in 'FirstAction' from 'SecondAction'. 

When exception occurs in 'FirstAction' I need the 'getSourcePageResolution' to get back to 'import.jsp' as the UrlBinding is saying so, but instead, it gets back to a default error page which I defined in web.xml as following:

<error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/jsp/error.jsp</location>
</error-page>

Here is the code for two actions and one jsp that I'm using

FirstAction.java

@UrlBinding("/example/import.action")
public class FirstAction implements ActionBean {
@DontValidate
public Resolution importTable() throws IOException  {
try {
// do something
} catch(Exception e) {
this.getContext().getValidationErrors().addGlobalError(new SimpleError(e.getMessage()));
return getContext().getSourcePageResolution();
}
return new RedirectResolution("/list.action");
}
}

SecondAction.java

public class SecondAction implements ActionBean {
@DefaultHandler
@DontValidate
public Resolution callImportTable() {
return new RedirectResolution (FirstAction.class, "importTable");
}
}

import.jsp

<stripes:link beanclass="com.example.action.SecondAction" event="callImportTable">
<input type="button" value="Import table" />
</stripes:link>

Is there any way to do the binding from 'SecondAction' to 'FirstAction' so  'getSourcePageResolution' shows the 'import.jsp' instead of 'error.jsp' ?

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users



------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Binding actionsBeans correctly

Nahid Seidi
Here is the code:

FirstAction.java

@SessionScope
@UrlBinding("/Student/newImport.action")
public class FirstAction implements ActionBean {
@SpringBean
private StudentFacade studentFacade;
private List<ImportExcel> importExcel;
    private String userCheckBox;
@DefaultHandler
@DontValidate
public Resolution edit() {
return new Forward("/import.jsp");
}

@DontValidate
public Resolution importStudents() throws IOException {

    try {
    //Here I put data into importExcel list
    } catch {}

      if (userCheckBox == null) {
      if(importExcel.size() > 0) {
      for(String error : importExcel) {
      this.getContext().getValidationErrors().add("userCheckBox",new SimpleError(error));
      }
      return getContext().getSourcePageResolution();
      }
      }

      try {
studentFacade.importStudents(importExcel);
} catch(Exception e) {
this.getContext().getValidationErrors().addGlobalError(new SimpleError(e.getMessage()));
return getContext().getSourcePageResolution();
}
    return new RedirectResolution("import.action");
}
@DontValidate
public Resolution importTable() throws IOException  {
try {
studentFacade.importStudents(importExcel);
} catch(Exception e) {
this.getContext().getValidationErrors().addGlobalError(new SimpleError(e.getMessage()));
return getContext().getSourcePageResolution();
}
return new RedirectResolution("/list.action");
}
}

There are two methods in firstAction (importStudents and importTable) in which when exception happens in 'importStudent' getSourcePage shows the 'import.jsp' but with the same senario in 'importTable' getSourcePages shows 'error.jsp'

SecondAction.java

public class SecondAction implements ActionBean  {
private List<ImportExcel> importExcel;
private String userCheckBox;
@DefaultHandler
@DontValidate
public Resolution callImportTable() throws IOException {
return new RedirectResolution (FirstAction.class, "importTable");
}

public List<ImportExcel> getImportExcel() {
return importExcel;
}

public void setImportExcel(List<ImportExcel> importExcel) {
this.importExcel = importExcel;
}
public String userCheckBox() {
return userCheckBox;
}

public void userCheckBox(String userCheckBox) {
this.userCheckBox = userCheckBox;
}
}

import.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<stripes:layout-render name="/WEB-INF/jsp/layout/default.jsp">
    <stripes:layout-component name="outer-contents">
<stripes:form beanclass="com.example.action.FirstAction">
<tags:labeled label="Overwrite existing data">
<stripes:checkbox name="userCheckBox"/>
</tags:labeled>
<stripes:errors field="userCheckBox"></stripes:errors>
<p>
<stripes:submit name="importStudents" value="Import"/>
</p>

<stripes:link beanclass="com.example.action.SecondAction" event="callImportTable">
<input type="button" value="Import table" />
</stripes:link>
</stripes:form>
</stripes:layout-component>
</stripes:layout-render>

The code is part of a bigger project, so I tried to make it as clear as possible.

By the way, it didn't work with extending the FirstAction.

/Nahid

On Fri, Feb 27, 2015 at 2:51 PM, Rick Grashel <[hidden email]> wrote:
Nahid,

Again, I can't see all the code you are using, but it looks like you can just have SecondAction extend FirstAction:

public class SecondAction extends FirstAction {
@DefaultHandler
@DontValidate
public Resolution callImportTable() {
return super.importTable();
}
} 

I can't see all the code you have, so this may or may not work.

-- Rick


On Fri, Feb 27, 2015 at 7:41 AM, Nahid Seidi <[hidden email]> wrote:
In following code I am calling a method in 'FirstAction' from 'SecondAction'. 

When exception occurs in 'FirstAction' I need the 'getSourcePageResolution' to get back to 'import.jsp' as the UrlBinding is saying so, but instead, it gets back to a default error page which I defined in web.xml as following:

<error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/jsp/error.jsp</location>
</error-page>

Here is the code for two actions and one jsp that I'm using

FirstAction.java

@UrlBinding("/example/import.action")
public class FirstAction implements ActionBean {
@DontValidate
public Resolution importTable() throws IOException  {
try {
// do something
} catch(Exception e) {
this.getContext().getValidationErrors().addGlobalError(new SimpleError(e.getMessage()));
return getContext().getSourcePageResolution();
}
return new RedirectResolution("/list.action");
}
}

SecondAction.java

public class SecondAction implements ActionBean {
@DefaultHandler
@DontValidate
public Resolution callImportTable() {
return new RedirectResolution (FirstAction.class, "importTable");
}
}

import.jsp

<stripes:link beanclass="com.example.action.SecondAction" event="callImportTable">
<input type="button" value="Import table" />
</stripes:link>

Is there any way to do the binding from 'SecondAction' to 'FirstAction' so  'getSourcePageResolution' shows the 'import.jsp' instead of 'error.jsp' ?

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users



------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users



------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users