S2: basic question on rest plugin

2009-11-14 Thread John . C . Cartwright
Hello All,

I'm experimenting with the rest plugin (2.1.8) using the example 
struts2-rest-showcase as a 
starting point.  I wanted to implement a simple search such that a URL like

http://localhost:8080/struts2-rest-showcase-2.1.8/orders?amount=66

returned a list of order with the amount of 66.  I approached this by adding an 
amount 
property to the controller and corresponding setter method and then modifying 
the 
controller's index method to use that value to constrain the results.

Problem is that the amount never gets set either on the controller or on the 
model.

Can someone please help me understand what's going on or suggest a better way 
to 
approach this problem?

Thanks!

--john



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: RE: S2: basic question on rest plugin

2009-11-14 Thread John . C . Cartwright
Thanks for your reply Martin, I think I now have it working using the attribute 
on the model.

--john

- Original Message -
From: Martin Gainty mgai...@hotmail.com
Date: Saturday, November 14, 2009 2:03 pm
Subject: RE: S2: basic question on rest plugin

 
 //First we need to define the attributes and methods for each 
 Entity to be added/removed
 //in this case it will be called Order
 
 package org.apache.struts2.rest.example;
 public class Order {
String id;
String clientName;
int amount; //here is the attribute you were 
 seeking BTW

public Order() {}
public Order(String id, String clientName, int amount) {
super();
this.id = id;
this.clientName = clientName;
this.amount = amount;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public String getClientName() {
return clientName;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + amount;
result = prime * result
+ ((clientName == null) ? 0 : clientName.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Order other = (Order) obj;
if (amount != other.amount)
return false;
if (clientName == null) {
if (other.clientName != null)
return false;
} else if (!clientName.equals(other.clientName))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
 }
 
 //take a look at the service class which feeds the Controller here 
 is on called OrdersService
 
 //whose purpose is to add to Orders or remove Orders via the 
 Service method
 
 package org.apache.struts2.rest.example;
 import java.util.*;
 public class OrdersService {
 
 //assuming we are populating our orders thru a HashMap similar to 
 this mechanism
private static MapString,Order orders = new 
 HashMapString,Order();private static int nextId = 6;
static {
orders.put(3, new Order(3, Bob, 33));
orders.put(4, new Order(4, Sarah, 44));
orders.put(5, new Order(5, Jim, 66));
}
 //get a single Order
public Order get(String id) {
return orders.get(id);
}
 //return a List all Orders 
public ListOrder getAll() {
return new ArrayListOrder(orders.values());
}
 //save a single Order
public void save(Order order) {
if (order.getId() == null) {
order.setId(String.valueOf(nextId++));
}
 //put into HashMap
orders.put(order.getId(), order);
}
 //removes an Order
public void remove(String id) {
orders.remove(id);
}
 }
 
 //we can configure our OrderService to interject necessary Orders 
 into our Controller 
 package org.apache.struts2.rest.example;
 
 import java.util.Collection;
 import org.apache.struts2.dispatcher.ServletActionRedirectResult;
 import org.apache.struts2.rest.DefaultHttpHeaders;
 import org.apache.struts2.rest.HttpHeaders;
 import org.apache.struts2.convention.annotation.Results;
 import org.apache.struts2.convention.annotation.Result;
 import org.apache.struts2.convention.annotation.ParentPackage;
 import org.apache.struts2.convention.annotation.Namespaces;
 import org.apache.struts2.convention.annotation.Namespace;
 import org.apache.struts2.convention.annotation.InterceptorRef;
 import com.opensymphony.xwork2.ModelDriven;
 import com.opensymphony.xwork2.Validateable;
 import com.opensymphony.xwork2.ValidationAwareSupport;
 
 @Results({
@Result(name=success, type=redirectAction, params = 
 {actionName , orders})
 })
 public class OrdersController extends ValidationAwareSupport 
 implements ModelDrivenObject, Validateable{  
private Order model = new Order(); //initial Order
private String id;
private CollectionOrder list;   //getAll returns this List
private OrdersService ordersService = new OrdersService(); 
 //Service will acquire order
 
// GET /orders/1
public HttpHeaders show() {
return new DefaultHttpHeaders(show);
}
 
// GET /orders
public HttpHeaders index() {
 //get the entire List of orders from ordersService
list = ordersService.getAll();
return new DefaultHttpHeaders(index)

S2: multiple file upload

2009-10-07 Thread John . C . Cartwright
Hello All,

I'm having trouble getting the FileUpload interceptor (v2.0.14) to work
w/ multiple files. My form looks like this:

s:file name=shapefile[0] label=shapefile /
s:file name=shapefile[1] label=shapefile /
s:file name=shapefile[2] label=shapefile /
s:submit name=upload/

and then my Action contains:

File[] shapefile;
String[] shapefileContentType;
String[] shapefileFileName;

w/ corresponding setters:

public void setShapefile(File[] files)
public void setShapefileContentType(String[] contentTypes)
public void setShapefileName(String[] names)

problem is that Parameters interceptor is trying to set
shapefile[1]FileName. I first tried elements w/o the index like:
s:file name=shapefile label=shapefile /
s:file name=shapefile label=shapefile /
s:file name=shapefile label=shapefile /

but then I got a single shapefile parameter w/o separators.

Can someone please help me w/ this?

Thanks!

--john


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



S2: @SkipValidation annotation

2009-09-21 Thread John . C . Cartwright
Hello All,

I'm having trouble getting the SkipValidation annotation to work.  I
have a single action w/ multiple methods. Some of the methods don't
require any input and I'd like to skip validation, e.g. 

@SkipValidation
public String list() {
   return(list);
}

However the annotation does not seem to prevent the validate method from
running and short circuiting the process. I'm using Struts 2.0.14 and
have included an excerpt from my struts.xml below.  Can someone please
help me here?

Thanks!

--john

action name=Test_* method={1}
class=gov.noaa.ngdc.mgg.scufn.action.TestAction
  result name=inputTestInput.jsp/result
  resultTestSuccess.jsp/result
  result name=listTestSuccess.jsp/result
/action

 

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



JSON plugin ignoring includeProperties parameter

2009-05-21 Thread John . C . Cartwright
Hello All,

I'm trying to use jsonplugin 0.32 w/ struts 2.0.14 and it seems that the
includeProperties parameter is being ignored.  My configuration looks like:

 result type=json
param name=excludeNullPropertiestrue/param
param name=includeProperties
items.*\.name
/param
 /result

Can someone please help me w/ what might be wrong?

Thanks!

--john



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



s:url does not include parameter

2009-04-14 Thread John . C . Cartwright
Hello All,

I'm trying to understand why the following does not produce a URL w/ the
requested parameter appended. Can someone please help me?

var url = s:url action=ListFeatures 
namespace=/secure/jsons:param name=status value=ALL //s:url;

//produces '/scufn/secure/json/ListFeatures.action'


Thanks!

--john


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



[S2] json-plugin: includeProperties being ignored?

2009-02-27 Thread John . C . Cartwright
Hello All,

I'm having trouble getting the json-plugin 0.32 to behave as I'd
expected.  The action is exposing a List of objects annotated as
@JSON(name=items) in the action.

I have my result configured as:
result type=json
param name=excludeNullPropertiestrue/param
param name=includeProperties
items.*\.name
/param
 /result

However the returned JSON has all of the properties for the objects in
the list.  Can someone please help me with what I'm doing wrong?

Thanks!

--john


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: [S2] url tag to construct href in different namespace

2008-07-25 Thread John . C . Cartwright
Just what I needed - thanks!

--john


- Original Message -
From: Dave Newton [EMAIL PROTECTED]
Date: Thursday, July 24, 2008 5:31 pm
Subject: Re: [S2] url tag to construct href in different namespace

 Namespaces typically begin with a /; try that.
 
 Dave
 
 --- On Thu, 7/24/08, John Cartwright [EMAIL PROTECTED] 
 wrote:
  From: John Cartwright [EMAIL PROTECTED]
  Subject: [S2] url tag to construct href in different namespace
  To: Struts Users Mailing List user@struts.apache.org
  Date: Thursday, July 24, 2008, 7:23 PM
  Hello All,
  
  I'm trying to use the url tag to construct a href which
  goes to a 
  different namespace.  It seems that all of the constructed
  URLs have the 
  same base as the original page.
  
  For example, given a page reached at:
  http://lynx.ngdc.noaa.gov:8080/tideloader/message/View.action
  
  The markup listed below produces this URL:
  

http://lynx.ngdc.noaa.gov:8080/tideloader/message/observation/View.action?localId=amkaCoperatorId=1

  when what I actually want is this URL:
  

http://lynx.ngdc.noaa.gov:8080/tideloader/observation/View.action?localId=amkaCoperatorId=1

  
 s:url action=View 
  forceAddSchemeHostAndPort=true 
  includeParams=none
  includeContext=true
  namespace=observation 
  scheme=http
   s:param name=localId
  value=key /
   s:param name=operatorId
  value=message.operatorId /
/s:url

 s:property value=key/
  
  
  
  Can someone please show me the correct way to do this?
  
  Thanks!
  
  --john
  
  
  --
 ---
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail:
  [EMAIL PROTECTED]
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: S2: chart result type not recognized

2008-01-05 Thread John . C . Cartwright
Hi Ian,

thanks for your reply.  For testing purposes, I'm simply calling it via URL:

http://localhost:8080/viewer-commons-2.0/chart/serverIronLoadChart.action

Strangely, I was able to get the chart example from the docs to run in
new context, I just can't seem to be able to integrate it into a more
complex existing application.  I'm assuming that the result type is not
being recognized, but don't see any errors in the logs and don't know
how to pursue debugging the problem.

By the way, I really enjoyed your recent Struts2 book!


--john

- Original Message -
From: Ian Roughley [EMAIL PROTECTED]
Date: Friday, January 4, 2008 7:43 am
Subject: Re: S2: chart result type not recognized

 How are you referencing the action?  I always use an img tag like 
 this:
 img src=serverIronLoadChart.action /
 
 /Ian
 
 -- 
 Ian Roughley
 From Down  Around, Inc.
 Consulting * Training / Mentoring * Agile Process * Open Source
 web: http://www.fdar.com - email: [EMAIL PROTECTED]
 
 
 
 John Cartwright wrote:
  Hello All,
 
  I'm having a little trouble getting a chart result type 
 configured 
  using the package declaration below.  Whenever I hit the 
 associated 
  URL, my browser prompts me to save a bin file  rather than 
  displaying the chart.  The bin file is a valid png, but somehow 
 Struts 
  is not recognizing the returned type.  Can anyone suggest what 
 I'm 
  doing wrong?
 
  Thanks!
 
  -- john
 
 
  package name=chart extends=jfreechart-default 
 namespace=/chart  action name=serverIronLoadChart
  
 class=gov.noaa.eds.arcims.tng.action.ServerIronLoadChartAction  
   result type=chart
 param name=width400/param
 param name=height300/param
  /result
   
/package
 
  --
 ---
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: RE: S2: chart result type not recognized

2008-01-05 Thread John . C . Cartwright
Thanks for your offer to help Martin!  

Listed below is the struts.xml, web.xml, and source for the Action class
(taken straight from the docs).
I'm testing it by simply typing the URL into the browser: 

http://localhost:8000/viewer-commons-2.0/chart/ViewModeration.action

I notice that if I embed the same URL into the src attribute of an img
element in an html page, the chart displays.  Makes me think perhaps the
mime type is not being set.  Is this possible?  In that case would I
potentially get different behavior from Apache/Tomcat on different
platforms (Mac vs Linux)?

--john

=== struts.xml ===
?xml version=1.0 encoding=UTF-8 ?
!DOCTYPE struts PUBLIC
-//Apache Software Foundation//DTD Struts Configuration 2.0//EN
http://struts.apache.org/dtds/struts-2.0.dtd;

struts

constant name=struts.devMode value=true /

constant name=struts.enable.DynamicMethodInvocation
value=false /
package name=viewer-commons extends=struts-default
global-results
result 
name=sessionTimeoutsessionTimeout.jsp/result
result name=unknownErrorerror.jsp/result
result name=sessionTimeout type=httpheader
param name=status204/param
param 
name=headers.exceptionSessionTimeoutException/param
param name=headers.class${exception}/param
/result
/global-results

global-exception-mappings
exception-mapping
exception=SessionTimeoutException
result=sessionTimeout
/exception-mapping
exception-mapping exception=java.lang.Exception
result=unknownError
/exception-mapping
/global-exception-mappings

action name=InitMapSession

class=gov.noaa.eds.arcims.tng.action.InitMapSessionAction /
action name=ListMapSessions

class=gov.noaa.eds.arcims.tng.action.ListMapSessionsAction
resultlistMapSessions.jsp/result
/action

/package

package name=chart extends=jfreechart-default
namespace=/chart
action name=ServerIronLoad

class=gov.noaa.eds.arcims.tng.action.ServerIronLoadChartAction
result name=success type=chart
param name=width400/param
param name=height300/param
/result
/action

action name=ViewModeration
class=com.jccartwright.ViewModerationChartAction
result name=success type=chart
param name=width400/param
param name=height300/param
/result
/action
/package

/struts


=== ViewModerationChartAction.java ===
/*
 * example taken from Struts docs
 * (http://struts.apache.org/2.0.11/docs/jfreechart-plugin.html)
 */
package com.jccartwright;


import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import org.apache.commons.lang.math.RandomUtils;

public class ViewModerationChartAction extends ActionSupport {

   private JFreeChart chart;

   public String execute() throws Exception {
  // chart creation logic...
  XYSeries dataSeries = new XYSeries(new Integer(1)); //pass a key
for this serie
  for (int i = 0; i = 100; i++) {
 dataSeries.add(i, RandomUtils.nextInt());
  }
  XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);

  ValueAxis xAxis = new NumberAxis(Raw Marks);
  ValueAxis yAxis = new NumberAxis(Moderated Marks);

  // set my chart variable
  chart =
 new JFreeChart(
Moderation Function,

S2: httpheader result type

2008-01-03 Thread John . C . Cartwright
Hello All,

in configuring the httpheader result type in the struts.xml file, is
there a way to access objects on the value stack?

Thanks!

--john


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: error in strutsel-exercise-taglib

2004-09-24 Thread John C Cartwright
Thanks for your reply, David.  I'm not sure that I understand though.  I 
am using tomcat 5.0.x and JSP2.0. However, when I change the taglib 
directive to:

%@ taglib prefix=html uri=http://jakarta.apache.org/struts/tags-html%
and try something like:
html:img src=${images[iconClosed]} height=16 width=16/
(where images is a HashMap in request scope), I get an error.  Indeed, 
the documentation for the html:img taglib specifies a RTExpr.

Can you clarify for me?
Thanks!
-- john
Karr, David wrote:
You don't need to use Struts-EL with Tomcat 5, if you're using JSP 2.0.
In fact, it won't work.  I don't know what this particular exception is,
but you can avoid this situation entirely by just not doing it.
--
=
John Cartwright
Associate Scientist
Geospatial Data Services Group
CIRES, National Geophysical Data Center/NOAA
(303) 497-6284
[EMAIL PROTECTED]
=
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


error in strutsel-exercise-taglib

2004-09-22 Thread John C Cartwright
Hello All,
I tried deploying the example webapp that comes with the 
contrib/struts-el taglibs and am getting the following exception 
accessing the index.jsp:

java.lang.NullPointerException
org.apache.struts.taglib.TagUtils.pageURL(TagUtils.java:1114)
org.apache.struts.taglib.TagUtils.computeURLWithCharEncoding(TagUtils.java:466)
org.apache.struts.taglib.TagUtils.computeURLWithCharEncoding(TagUtils.java:329)
org.apache.struts.taglib.html.LinkTag.calculateURL(LinkTag.java:475)
org.apache.struts.taglib.html.LinkTag.doStartTag(LinkTag.java:334)
org.apache.strutsel.taglib.html.ELLinkTag.doStartTag(ELLinkTag.java:666)
org.apache.jsp.index_jsp._jspx_meth_html$1el_link_0(index_jsp.java:146)
org.apache.jsp.index_jsp._jspService(index_jsp.java:118)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
Can anyone suggest what the problem might be?  Struts version 1.2.4, 
Tomcat 5.0.25.

Thanks!
-- john
=
John Cartwright
Associate Scientist
Geospatial Data Services Group
CIRES, National Geophysical Data Center/NOAA
(303) 497-6284
[EMAIL PROTECTED]
=
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]