Hello, Im having an issue getting json working with the struts-jquery-plugin-2.1.0
I have included the struts2-json-plugin-2.1.8.1 in my classpath as well.
Im sure that I have my struts-jquery-plugin configured correctly because the grid loads, but doesnt load the data its supposed to get from the action class that has been json'ized.
The documentation with the json plugin and the struts-jquery plugin leaves ALOT of gaps that I cant even find with examples/tutorials, so I come to the community at stackoverflow.
My action class has a property called gridModel thats a List with a basic POJO called Customer. Customer is a pojo with one property, id.
I have a factory that supplies the populated List to the actions List property which i mentioned called gridModel.
Heres how i set up my struts.xml file:
<constant name="struts.devMode" value="true"/>
<constant name="struts.objectFactory" value="guice"/>
<package name="org.webhop.ywdc" namespace="/" extends="struts-default,json-default">
<result-types>
<result-type name="json" class="com.googlecode.jsonplugin.JSONResult">
</result-type>
</result-types>
<action name="login" class="org.webhop.ywdc.LoginAction" >
<result type="json"></result>
<result name="success" type="dispatcher">/pages/uiTags/Success.jsp</result>
<result name="error" type="redirect">/pages/uiTags/Login.jsp</result>
<interceptor-ref name="cookie">
<param name="cookiesName">JSESSIONID</param>
</interceptor-ref>
</action>
<action name="logout" class="org.webhop.ywdc.LogoutAction" >
<result name="success" type="redirect">/pages/uiTags/Login.jsp</result>
</action>
</package>
In the struts.xml file i set the
and in my action i listed
in the action configuration.
Heres my jsp page that the action loads:
<%@ taglib prefix="s" uri="/struts-tags" %
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%
<%@ page language="java" contentType="text/html" import="java.util.*"%
Welcome, you have logged in!
<s:url id="remoteurl" action="login"/>
<sjg:grid
id="gridtable"
caption="Customer Examples"
dataType="json"
href="%{remoteurl}"
pager="false"
gridModel="gridModel"
>
<sjg:gridColumn name="id" key="true" index="id" title="ID" formatter="integer" sortable="false"/>
</sjg:grid>
Welcome, you have logged in. <br />
<b>Session Time: </b><%=new Date(session.getLastAccessedTime())%>
<h2>Password:<s:property value="password"/></h2>
<h2>userId:<s:property value="userId"/></h2>
<br />
<a href="<%= request.getContextPath() %>/logout.action">Logout</a><br /><br />
ID: <s:property value="id"/>
session id: <s:property value="JSESSIONID"/>
</body>
Im not really sure how to tell what json the json plugin is creating from the action class.
If i did know how i could tell if it wasnt formed properly.
As far as I know if I specificy in my action configuration
in struts.xml, that the grid, which is set to read json and knows to look for "gridModel" will then automatically load the json to the grid, but its not.
Heres my action class:
public class LoginAction extends ActionSupport {
public String JSESSIONID;
public int id;
private String userId;
private String password;
public Members member;
public List<Customer> gridModel;
public String execute()
{
Cookie cookie = new Cookie("ywdcsid", password);
cookie.setMaxAge(3600);
HttpServletResponse response = ServletActionContext.getResponse();
response.addCookie(cookie);
HttpServletRequest request = ServletActionContext.getRequest();
Cookie[] ckey = request.getCookies();
for(Cookie c: ckey)
{
System.out.println(c.getName() + "/cookie_name + " + c.getValue() + "/cookie_value");
}
Map requestParameters = ActionContext.getContext().getParameters();//getParameters();
String[] testString = (String[])requestParameters.get("password");
String passwordString = testString[0];
String[] usernameArray = (String[])requestParameters.get("userId");
String usernameString = usernameArray[0];
Injector injector = Guice.createInjector(new GuiceModule());
HibernateConnection connection = injector.getInstance(HibernateConnection.class);
AuthenticationServices currentService = injector.getInstance(AuthenticationServices.class);
currentService.setConnection(connection);
currentService.setInjector(injector);
member = currentService.getMemberByUsernamePassword(usernameString, passwordString);
userId = member.getUsername();
password = member.getPassword();
CustomerFactory customerFactory = new CustomerFactory();
gridModel = customerFactory.getCustomers();
if(member == null)
{
return ERROR;
}
else
{
id = member.getId();
Map session = ActionContext.getContext().getSession();
session.put(usernameString, member);
return SUCCESS;
}
}
public String logout() throws Exception
{
Map session = ActionContext.getContext().getSession();
session.remove("logged-in");
return SUCCESS;
}
public List<Customer> getGridModel()
{
return gridModel;
}
public void setGridModel(List<Customer> gridModel)
{
this.gridModel = gridModel;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getUserId()
{
return userId;
}
public void setUserId(String userId)
{
this.userId = userId;
}
public String getJSESSIONID() {
return JSESSIONID;
}
public void setJSESSIONID(String jsessionid) {
JSESSIONID = jsessionid;
}
}
Please help me with this problem. You will make my week, as this is a major
bottleneck for me :(
thanks so much,
thebravedave