1

I am pretty familiar with Struts 2... Since 3 days I've been stuck in a very strange problem.
I have many attributes in my action class; some are Integers, the others are Strings.
I know I have created both of the getters/setters for all my attributes
showcase extends struts-default and json-default because i need the class to render a json table i am using the struts2-jquery gridtag....
none of my attributes are being printed exept sord,sdix,page.. those defined by the tag

My Action Class

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.ParentPackage;

import amz.votrerepas.dao.CategorieDao;
import amz.votrerepas.dao.CategorieDaoImplementation;
import amz.votrerepas.dao.ProduitDao;
import amz.votrerepas.dao.ProduitDaoImplementation;
import amz.votrerepas.models.Produit;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

@ParentPackage(value = "showcase")
public class ProduitAction extends ActionSupport implements Preparable{

private static final long serialVersionUID = 947577563329037436L;
private List<Produit> produits;

private String searchOper = "asc"; // Search operator
private String sord; // sorting order - asc or desc
private String sidx; // get index row - i.e. user click to sort.
private String searchField; // Search Field
private String searchString; // The Search String
private String oper;
private Integer rows = 0; 
private Integer page = 0; 
private Integer total = 0; 
private Integer records; 
private String myeditOptions;

@Override
public void prepare() throws Exception {
    CategorieDao catdao = new CategorieDaoImplementation();
    Map<Long, String> listEditOptions = catdao.getAllCategories();
    List<String> arraywithresulttupels = new ArrayList<String>();
    for (Long key : listEditOptions.keySet()) {
        arraywithresulttupels.add(""+key+":"+listEditOptions.get(key));
    }
    Collections.sort(arraywithresulttupels);
    myeditOptions = "{value:'" + StringUtils.join(arraywithresulttupels, ";")
            + "'}";
}

@Override
public String execute() throws Exception {
    ProduitDao dao = new ProduitDaoImplementation();
    produits = dao.getallProducts();
    return SUCCESS;
}

public String getJSON() throws Exception {
    return execute();
}

public List<Produit> getProduits() {
    return produits;
}

public void setProduits(List<Produit> produits) {
    this.produits = produits;
}

public String getSearchOper() {
    return searchOper;
}

public void setSearchOper(String searchOper) {
    this.searchOper = searchOper;
}

    public String getSord() {
    return sord;
}

public void setSord(String sord) {
    this.sord = sord;
}

public String getSidx() {
    return sidx;
}

public void setSidx(String sidx) {
    this.sidx = sidx;
}

public String getSearchField() {
    return searchField;
}

public void setSearchField(String searchField) {
    this.searchField = searchField;
}

public String getSearchString() {
    return searchString;
}

public void setSearchString(String searchString) {
    this.searchString = searchString;
}

public String getOper() {
    return oper;
}

public void setOper(String oper) {
    this.oper = oper;
}

public Integer getRows() {
    return rows;
}

public void setRows(Integer rows) {
    this.rows = rows;
}

public Integer getPage() {
    return page;
}

public void setPage(Integer page) {
    this.page = page;
}

public Integer getTotal() {
    return total;
}

public void setTotal(Integer total) {
    this.total = total;
}

public Integer getRecords() {
    return records;
}

public void setRecords(Integer records) {
    this.records = records;
}
public String getMyeditOptions() {
    return myeditOptions;
}
public void setMyeditOptions(String myeditOptions) {
    this.myeditOptions = myeditOptions;
}
}

SomeWhere in My JSP page

    <s:property value="%{myeditOptions}"/>
    <s:property value="%{page}"/>

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="false" />

<!-- ******************************** Comptes Actions ******************************** -->
<package name="default" extends="struts-default" namespace="/auth">
    <action name="authenticate" class="amz.votrerepas.actions.Authenticate" method="execute">
        <result name="success" type="redirectAction">
            <param name="actionName">indexProduits</param>
            <param name="namespace">/products</param>
        </result>
        <result name="error">/pages/welcome.jsp</result>
    </action>
</package>

<!-- ******************************** Produits Actions ******************************** -->

<package name="categories" extends="struts-default" namespace="/products">

    <action name="indexProduits" class="amz.votrerepas.actions.CategorieAction" method="execute">
        <result name="success">/pages/admin/products.jsp</result>
    </action>

    <action name="edit-categorie-grid-entry" class="amz.votrerepas.actions.CategorieEditAction" method="execute">
        <result name="success"> /pages/admin/products.jsp </result>
        <result name="input"> /pages/admin/products.jsp </result>
    </action>

    <action name="edit-produit-grid-entry" class="amz.votrerepas.actions.ProduitEditAction" method="execute">
        <result name="success"> /pages/admin/products.jsp </result>
        <result name="input"> /pages/admin/products.jsp </result>
    </action>
</package>

<!-- ******************************** Json Actions ******************************** -->
<package name="showcase" extends="struts-default,json-default" namespace="/jquery">

    <action name="jsontableCats" class="amz.votrerepas.actions.CategorieAction" method="getJSON">
        <result name="success" type="json" />
    </action>

    <action name="jsontableProds" class="amz.votrerepas.actions.ProduitAction"  method="getJSON">
        <result name="success" type="json" />
    </action>
</package>
</struts>

My Lib Folder

antlr-2.7.6
antlr-2.7.7
asm-3.3.1
asm-3.3
asm-commons-3.3
asm-tree-3.3
cglib-2.2.2
codegen-0.5.9
commonj.sdo-2.1.1.v201112051852
commons-collections-3.1
commons-fileupload-1.2.2
commons-io-2.0.1
commons-lang-2.6
commons-lang3-3.1
dom4j-1.6.1
ecj-3.7.2
eclipselink-2.4.0
freemarker-2.3.19
guava-13.0.1
hibernate3
hibernate-commons-annotations-4.0.1.Final
hibernate-core-4.1.7.Final
hibernate-entitymanager-4.1.7.Final
hibernate-jpa-2.0-api-1.0.0.Final
hibernate-validator-4.3.0.Final
javassist-3.11.0.GA
javassist-3.12.0.GA
javassist-3.15.0-GA
javax.inject-1
javax.persistence-2.0.4.v201112161009
jboss-logging-3.1.0.GA
jboss-transaction-api_1.1_spec-1.0.0.Final
joda-time-1.6
json-lib-2.3-jdk15
jsr305-1.3.9
jta-1.1
log4j-1.2.16
mysema-commons-lang-0.2.4
mysql-connector-java-5.1.25-bin
ognl-3.0.6
querydsl-apt-3.1.1
querydsl-codegen-3.1.1
querydsl-core-3.1.1
querydsl-jpa-3.1.1
querydsl-jpa-3.1.1-apt
querydsl-jpa-3.1.1-javadoc
querydsl-sql-3.1.1
slf4j-api-1.6.1
slf4j-log4j12-1.6.1
struts2-convention-plugin-2.3.14
struts2-core-2.3.14
struts2-jquery-grid-plugin-3.5.1
struts2-jquery-plugin-3.5.1
struts2-json-plugin-2.3.14
validation-api-1.0.0.GA
xwork-core-2.3.14

The Value of page is shown but the value of myeditOptions is not..... Pleeeease help

Lord-zed
  • 11
  • 3
  • Are you sure it is populated? Did you check with debugger to see if it has a value before it reaches the jsp? – Panos May 28 '13 at 13:41
  • Pano yes i debug it the value is not null i initialize it in the prepare methode – Lord-zed May 28 '13 at 13:53
  • try : or : – Panos May 28 '13 at 13:55
  • @panos just tried them it didn't work..... – Lord-zed May 28 '13 at 14:00
  • @Lord-zed You should post the entire action code including imports and `struts.xml`. – Roman C May 28 '13 at 14:22
  • @RomanC I just edited my post – Lord-zed May 28 '13 at 14:48
  • 1
    @Lord-zed Are you sure the `prepare` is called? – Roman C May 28 '13 at 15:09
  • @RomanC yes it is i print the value of my variable into the console and it's shown as i want it to be! BTW i have boyh of commons-lang2 and commons-lang3 in my lib folder for i18n reasons... Could it be the problem – Lord-zed May 28 '13 at 15:13
  • Could you post everything you have in the lib? – Roman C May 28 '13 at 15:20
  • here is a printscr of my lib folder https://docs.google.com/file/d/0BxzbVUmM8noRbzRWOVVGcm5DMlU/edit?usp=sharing – Lord-zed May 28 '13 at 15:31
  • @Lord-zed Add the text content of your lib directory to the question, don't make people chase down your information. – Dave Newton May 28 '13 at 15:36
  • @DaveNewton there it is.... – Lord-zed May 28 '13 at 15:59
  • Can you try setting a dummy value to myeditOptions in prepare method ? Something like "foobar". – Andrea Ligios May 28 '13 at 16:17
  • Is an exception being thrown then? Is dev mode enabled in struts.xml? Try a wrapping the prepare statements with a try{}catch{print error message and rethrow}. What you show should work if an exception isn't happening... and you have a custom stack which could contain all kinds of magic. – Quaternion May 28 '13 at 16:21
  • @AndreaLigios yes i just tried but it didn't work... all the String from my action class aren't printed in the page... – Lord-zed May 28 '13 at 16:22
  • Couple of things to try: 1.set some other value instead of a json, 2.try setting "page" in prepare and look for the new value in jsp, 3.rename the variable "myeditOptions" to something like "myOptions" – Sajan Chandran May 28 '13 at 16:27
  • @Quaternion dev mode is enabled, i just surrounded the prepare() with try catch but no exception is raised... but i don't use any interceptor or stack... should I?? – Lord-zed May 28 '13 at 16:30
  • @SajanChandran i tried them all nothing has changed but when i created a new attribute as Integer it wasn't printed i think i have a value stack problem.... – Lord-zed May 28 '13 at 16:48
  • @Lord-zed You have duplicate libraries in the lib, remove duplicates, remove asm-3.3.1, antlr 2.7.6, javassist-xxx add javassist-3.17.1-GA, remove slf4j. – Roman C May 28 '13 at 16:49
  • @RomanC just removed all the duplicates but commons-lang evrything is still working but i am having the same problem – Lord-zed May 28 '13 at 17:01
  • Comment `jsontableProds` and post `products.jsp`. – Roman C May 28 '13 at 17:10
  • @Lord-zed well the parent package is "showcase" what does this package extend? Is it struts-default? Are you getting other values form the action correctly? What if you try using the whole method in the parameter tag ie: "getMyeditOptions()"? What happens if you set the value manually within the execute method? – Quaternion May 28 '13 at 17:22
  • @RomanC should i comment the action in struts.xml??? because if i do the prepare method will never be executed! – Lord-zed May 28 '13 at 17:26
  • @Quaternion showcase extends struts-default and json-default because i need the class to render a json table i am using the struts2-jquery gridtag....none of my attributes are being printed exept sord,sdix,page.. those defined by the tag... the getter does not work in the either!!! – Lord-zed May 28 '13 at 17:40
  • @Lord-zed You should comment it, because it refer the same class. It's not true it will execute by the prepare interceptor. – Roman C May 28 '13 at 18:34
  • @RomanC i just comment it and debug it the prepare statement was correctly executed but the attribute wasn't printed. I also tried to put the String in the valueStack but nothing... this has started to get reaaaaaaly wired!! – Lord-zed May 28 '13 at 18:52
  • Wired is a weird way to say weird – Andrea Ligios May 28 '13 at 19:34
  • @AndreaLigios hhhhhh sorry not a native speaker!!! english is my fourth language! my first is java lol – Lord-zed May 28 '13 at 19:42
  • Looks like you started to disclose your problem but I want to see how did you try to "put the String in the valueStack"? – Roman C May 28 '13 at 20:18
  • @RomanC I did this
    `ValueStack stack = ActionContext.getContext().getValueStack(); Map context = new HashMap(); context.put("myopdtions",myeditOptions ); stack.push(context);`
    Following this link http://www.tutorialspoint.com/struts_2/struts_value_stack_ognl.htm
    – Lord-zed May 28 '13 at 20:36
  • http://struts.apache.org/release/2.3.x/struts2-core/apidocs/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.html Try to add this debugging interceptor and check whether that value is available in value stack. – MohanaRao SV May 29 '13 at 04:46
  • Please try CTRL+SHIFT+K in Firefox and `$.get("yourserver/jquery/jsontableProds.action", function(data){ alert(data.myeditOptions);});` – Andrea Ligios May 29 '13 at 08:54
  • @MohanaRaoSV thanks i debugged it and found the attribute with the correct value but i still cannot print it here is the xml output of the debug {value:'12:rprprp;14:kokoko;15:kozo;16:zararassss;17:llololedzdezrf;19:zooooo;1:titizzaa;20:roooooo;21:toooooo;22:hooooooooo;23:haaaaaaaaaa;24:moooout;4:jijixxoo;9:rosexxo'} – Lord-zed May 29 '13 at 15:20

2 Answers2

0

@Lord-zed I see that you populate myEditOptions only on prepare() method. It is not populated again when the "execute" action is hit. So either you must populate it again in execute() or put a hidden field in the jsp of the prepare action to post it back to the "execute" action. I would propose to repopulate it in the execute().

Panos
  • 7,227
  • 13
  • 60
  • 95
-1

There is no need to typecast the getters and setters, You should create different file of getters and setters and DAO too.

  • 2
    I don't see any typecasting; can you be more specific? Different file of getters and setters? It's unclear what you're referring to. In any case, I'm not sure how this is an answer. – Dave Newton May 28 '13 at 18:03
  • 1
    I don't see what you mean by different file for getters and setters the DAO seems to work fine for me too. could you be more clear please?? – Lord-zed May 28 '13 at 18:14