You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by pirzada rashid <pi...@gmail.com> on 2012/10/15 07:23:23 UTC
person.getId() not set with url paramter using NamedVariablePatternMatcher
Hi,
I am not sure what is wrong. I tried alot.
*In Short:* *Below Scenario 1 is fine but problem with Scenario 2 where
this.person.getId() is not set thus generating error*
*Scenario 1: Working fine*
*URL generated*
http://localhost:8000/1_Struts2_Tiles_mvn/person/edit?person.id=8
*struts.xml action method*
<action name="edit" class="com.myapp.action.PersonAction"
method="getPersonById">
<interceptor-ref name="byPassValidation"/>
<param name="person.id">%{person.id}</param>
<result name="success" type="tiles">/person.edit.tiles</result>
</action>
*URL is generated in simple Grid*
<s:url id="editURL" action="edit" >
<s:param name="person.id">%{id}</s:param>
</s:url>
<s:a href="%{editURL}"><i class="icon-edit"></i></s:a>
*Action Class Method*
public String getPersonById() throws Exception {
LOG.debug("getPersonById() = {} executed---->>>>", this.person.getId());
person = personDAO.get(this.person.getId());
return SUCCESS;
}
*Scenario 2: Changed*
*PROBLEM:* *this.person.getId() is not set thus generating error*
*URL generated which is fine. I need that.*
http://localhost:8000/1_Struts2_Tiles_mvn/person/edit/8
*Enabled in struts.xml*
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="regex"/>
*URL is generated in simple Grid*
<s:url id="editURL" action="edit/%{id}" > </s:url>
<s:a href="%{editURL}"><i class="icon-edit"></i></s:a>
*OR*
<s:set var="person.id" value="%{id}"/>
<s:url id="editURL" action="edit/%{person.id}" />
<s:a href="%{editURL}"><i class="icon-edit"></i></s:a>
*struts.xml*
<package name="person" namespace="/person" extends="tiles-default">
<interceptors>
<interceptor-stack name="byPassValidation">
<interceptor-ref name="params"/>
<interceptor-ref name="validation">
<param
name="excludeMethods">getAllPersons,getPersonById,input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param
name="excludeMethods">getAllPersons,getPersonById,input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="edit/{person.id}"
class="com.myapp.action.PersonAction" method="getPersonById">
<interceptor-ref name="byPassValidation"/>
<result name="success" type="tiles">/person.edit.tiles</result>
</action>
</package>
*Action Class Method*
public String getPersonById() throws Exception {
LOG.debug("getPersonById() = {} executed---->>>>", this.person.getId());
person = personDAO.get(this.person.getId());
return SUCCESS;
}
*ERROR:*
java.lang.NullPointerException
com.myapp.action.PersonAction.getPersonById(PersonAction.java:61)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
*CONSOLE:*
07:39:24,424 DEBUG DefaultActionProxy:68 - Creating an
DefaultActionProxy for namespace /person and action name edit/8
07:39:24,425 DEBUG AbstractMatcher:68 - Attempting to match 'edit/8'
to a wildcard pattern, 2 available
07:39:24,425 DEBUG AbstractMatcher:68 - Value matches pattern 'edit/{person.id}'
07:39:24,428 DEBUG ParametersInterceptor:68 - Setting params
07:39:24,428 DEBUG DefaultWorkflowInterceptor:68 - Skipping
Interceptor... Method [getPersonById] found in exclude list.
07:39:24,429 DEBUG DefaultActionInvocation:68 - Executing action
method = getPerso
Re: person.getId() not set with url paramter using NamedVariablePatternMatcher
Posted by Lukasz Lenart <lu...@apache.org>.
2012/10/15 pirzada rashid <pi...@gmail.com>:
> One Question: How can I understand interceptors more. They have certain
> stacking otherwise problems. Is there anyway to understand, How to stack
> interceptors properly to make things work?
On the beginning use stacks defined by framework, you can just tweak
them a bit - add exclude/include methods and so on. Do not change the
order of them, do not remove interceptors if you don't know what do
they do.
If you have a large app or when you are going to deploy it, you can
try to optimise interceptor stack to your needs - removing
interceptors not used in your app (eg. FileUploadInterceptor) or
creating dedicated stacks for each package. Thus will speed up your
application.
http://struts.apache.org/2.x/docs/interceptors.html
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: person.getId() not set with url paramter using NamedVariablePatternMatcher
Posted by pirzada rashid <pi...@gmail.com>.
Thanks alot. That was interceptor problem.
One Question: How can I understand interceptors more. They have certain
stacking otherwise problems. Is there anyway to understand, How to stack
interceptors properly to make things work?
Hope you understand, What I want to ask.
Apache rewrite/reverse proxy
Posted by "Ben Mati, Abdelkader" <Ab...@bnc.ca>.
Hello Listers,
I have back end website running on Tomcat using struts with the following url http://local.domain.com/app. External user access the website through apache proxy with the following url http://www.domain.com/user1 (user1, user2, etc... It’s uri specific to each user). I want to use apache rewrite or/ and reverse proxy directive to translate the url like http://www.domain.com/user1 into http://local.domain.com/app?user=user1
Can some apache guru help me please?
Thanks,
Abdel
-----Original Message-----
From: Lukasz Lenart [mailto:lukaszlenart@apache.org]
Sent: October 15, 2012 2:31 AM
To: Struts Users Mailing List
Subject: Re: person.getId() not set with url paramter using NamedVariablePatternMatcher
2012/10/15 pirzada rashid <pi...@gmail.com>:
> Thanks for the reply. I have commented person =
> personDAO.get(this.getId());. To make things more clear. Just wanted
> to see Method prints "id" passed in URL. Below are changes.
> See this line below 10:56:05,583 DEBUG PersonAction:62 -
> getPersonById() = null executed---->>>> . I get id value null. Thats the problem.
>
> URL : http://localhost:8000/1_Struts2_Tiles_mvn/person/edit/8
>
> JSP Page:
>
> <s:url id="editURL" action="edit/%{id}" /> <s:a href="%{editURL}"><i
> class="icon-edit"></i></s:a>
>
> struts.xml
>
> <action name="edit/*" class="com.myapp.action.PersonAction"
> method="getPersonById" >
> <param name="id">{1}</param>
> <interceptor-ref name="byPassValidation"/>
> <result name="success" type="tiles">/person.edit.tiles</result>
> </action>
>
> Action Class method
>
> public String getPersonById() throws Exception {
> LOG.debug("getPersonById() = {} executed---->>>>", this.getId());
> return SUCCESS;
> }
>
> CONSOLE -> Stacktrace
>
> 10:56:05,578 DEBUG DefaultActionProxy:68 - Creating an
> DefaultActionProxy for namespace /person and action name edit/8
> 10:56:05,581 DEBUG AbstractMatcher:68 - Attempting to match 'edit/8'
> to a wildcard pattern, 2 available
> 10:56:05,581 DEBUG AbstractMatcher:68 - Value matches pattern 'edit/*'
> 10:56:05,582 DEBUG ParametersInterceptor:68 - Setting params
> 10:56:05,582 DEBUG DefaultWorkflowInterceptor:68 - Skipping Interceptor...
> Method [getPersonById] found in exclude list.
> 10:56:05,582 DEBUG DefaultActionInvocation:68 - Executing action
> method = getPersonById
> 10:56:05,583 DEBUG PersonAction:62 - getPersonById() = null
> executed---->>>>
I think the problem is how you defined your stack - it's missing a lot of other interceptors. Take a look how it is defined in Showcase App [1]
[1] https://svn.apache.org/repos/asf/struts/struts2/trunk/apps/showcase/src/main/resources/struts.xml
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
CONFIDENTIALIT� : Ce document est destin� uniquement � la personne ou � l'entit� � qui il est adress�.
L'information apparaissant dans ce document est de nature l�galement privil�gi�e et confidentielle. Si vous n'�tes pas
le destinataire vis� ou la personne charg�e de le remettre � son destinataire, vous �tes, par la pr�sente, avis� que toute
lecture, usage, copie ou communication du contenu de ce document est strictement interdit. De plus, vous �tes pri� de
communiquer avec l'exp�diteur sans d�lai ou d'�crire � confidentialite@bnc.ca et de d�truire ce document
imm�diatement.
CONFIDENTIALITY: This document is intended solely for the individual or entity to whom it is addressed. The
information contained in this document is legally privileged and confidential. If you are not the intended recipient or the
person responsible for delivering it to the intended recipient, you are hereby advised that you are strictly prohibited from
reading, using, copying or disseminating the contents of this document. Please inform the sender immediately or write
to confidentiality@nbc.ca and delete this document immediately.
Re: person.getId() not set with url paramter using NamedVariablePatternMatcher
Posted by Lukasz Lenart <lu...@apache.org>.
2012/10/15 pirzada rashid <pi...@gmail.com>:
> Thanks for the reply. I have commented person =
> personDAO.get(this.getId());. To make things more clear. Just wanted to see
> Method prints "id" passed in URL. Below are changes.
> See this line below 10:56:05,583 DEBUG PersonAction:62 - getPersonById() =
> null executed---->>>> . I get id value null. Thats the problem.
>
> URL : http://localhost:8000/1_Struts2_Tiles_mvn/person/edit/8
>
> JSP Page:
>
> <s:url id="editURL" action="edit/%{id}" />
> <s:a href="%{editURL}"><i class="icon-edit"></i></s:a>
>
> struts.xml
>
> <action name="edit/*" class="com.myapp.action.PersonAction"
> method="getPersonById" >
> <param name="id">{1}</param>
> <interceptor-ref name="byPassValidation"/>
> <result name="success" type="tiles">/person.edit.tiles</result>
> </action>
>
> Action Class method
>
> public String getPersonById() throws Exception {
> LOG.debug("getPersonById() = {} executed---->>>>", this.getId());
> return SUCCESS;
> }
>
> CONSOLE -> Stacktrace
>
> 10:56:05,578 DEBUG DefaultActionProxy:68 - Creating an DefaultActionProxy
> for namespace /person and action name edit/8
> 10:56:05,581 DEBUG AbstractMatcher:68 - Attempting to match 'edit/8' to a
> wildcard pattern, 2 available
> 10:56:05,581 DEBUG AbstractMatcher:68 - Value matches pattern 'edit/*'
> 10:56:05,582 DEBUG ParametersInterceptor:68 - Setting params
> 10:56:05,582 DEBUG DefaultWorkflowInterceptor:68 - Skipping Interceptor...
> Method [getPersonById] found in exclude list.
> 10:56:05,582 DEBUG DefaultActionInvocation:68 - Executing action method =
> getPersonById
> 10:56:05,583 DEBUG PersonAction:62 - getPersonById() = null executed---->>>>
I think the problem is how you defined your stack - it's missing a lot
of other interceptors. Take a look how it is defined in Showcase App
[1]
[1] https://svn.apache.org/repos/asf/struts/struts2/trunk/apps/showcase/src/main/resources/struts.xml
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: person.getId() not set with url paramter using NamedVariablePatternMatcher
Posted by pirzada rashid <pi...@gmail.com>.
Thanks for the reply. I have commented person =
personDAO.get(this.getId());. To make things more clear. Just wanted to see
Method prints "id" passed in URL. Below are changes.
See this line below 10:56:05,583 DEBUG PersonAction:62 - getPersonById() =*null
*executed---->>>> . I get id value null. Thats the problem.
*URL :* http://localhost:8000/1_Struts2_Tiles_mvn/person/edit/8
*JSP Page:*
<s:url id="editURL" action="edit/%{id}" />
<s:a href="%{editURL}"><i class="icon-edit"></i></s:a>
*struts.xml*
<action name="edit/*" class="com.myapp.action.PersonAction"
method="getPersonById" >
<param name="id">{1}</param>
<interceptor-ref name="byPassValidation"/>
<result name="success" type="tiles">/person.edit.tiles</result>
</action>
*Action Class method*
public String getPersonById() throws Exception {
LOG.debug("getPersonById() = {} executed---->>>>", this.getId());
return SUCCESS;
}
CONSOLE -> Stacktrace
10:56:05,578 DEBUG DefaultActionProxy:68 - Creating an DefaultActionProxy
for namespace /person and action name edit/8
10:56:05,581 DEBUG AbstractMatcher:68 - Attempting to match 'edit/8' to a
wildcard pattern, 2 available
10:56:05,581 DEBUG AbstractMatcher:68 - Value matches pattern 'edit/*'
10:56:05,582 DEBUG ParametersInterceptor:68 - Setting params
10:56:05,582 DEBUG DefaultWorkflowInterceptor:68 - Skipping Interceptor...
Method [getPersonById] found in exclude list.
10:56:05,582 DEBUG DefaultActionInvocation:68 - Executing action method =
getPersonById
10:56:05,583 DEBUG PersonAction:62 - getPersonById() =* null *
executed---->>>>
Re: person.getId() not set with url paramter using NamedVariablePatternMatcher
Posted by Łukasz Lenart <lu...@gmail.com>.
2012/10/15 pirzada rashid <pi...@gmail.com>:
> public String getPersonById() throws Exception {
> LOG.debug("getPersonById() = {} executed---->>>>",
> this.getId());
> person = personDAO.get(this.getId());
>
> return SUCCESS;
> }
>
> **ERROR:**
>
> java.lang.NullPointerException
>
> com.myapp.action.PersonAction.getPersonById(PersonAction.java:61)
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> java.lang.reflect.Method.invoke(Method.java:597)
If this is a full stack, then the personDAO is null and that's why you get NPE.
Regards
--
Łukasz
mobile +48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: person.getId() not set with url paramter using NamedVariablePatternMatcher
Posted by pirzada rashid <pi...@gmail.com>.
*More cleaned code for understanding.*
I am not sure what is wrong. I tried alot.
**PROBLEM:** *this.getId() is not set thus generating error*
**URL generated which is fine. I need that.**
http://localhost:8000/1_Struts2_Tiles_mvn/person/edit/8
**Enabled in struts.xml**
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace"
value="false"/>
<constant name="struts.patternMatcher" value="regex"/>
**URL is generated in simple Grid. Setter/Getter are in Action Class**
<s:url id="editURL" action="edit/%{id}" > </s:url>
<s:a href="%{editURL}"><i
class="icon-edit"></i></s:a>
**struts.xml**
<package name="person" namespace="/person" extends="tiles-default">
<interceptors>
<interceptor-stack name="byPassValidation">
<interceptor-ref name="params"/>
<interceptor-ref name="validation">
<param
name="excludeMethods">getAllPersons,getPersonById,input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param
name="excludeMethods">getAllPersons,getPersonById,input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="edit/{id}" class="com.myapp.action.PersonAction"
method="getPersonById">
<interceptor-ref name="byPassValidation"/>
<result name="success"
type="tiles">/person.edit.tiles</result>
</action>
</package>
**Action Class Method**
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getPersonById() throws Exception {
LOG.debug("getPersonById() = {} executed---->>>>",
this.getId());
person = personDAO.get(this.getId());
return SUCCESS;
}
**ERROR:**
java.lang.NullPointerException
com.myapp.action.PersonAction.getPersonById(PersonAction.java:61)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
**CONSOLE:**
07:39:24,424 DEBUG DefaultActionProxy:68 - Creating an
DefaultActionProxy for namespace /person and action name edit/8
07:39:24,425 DEBUG AbstractMatcher:68 - Attempting to match 'edit/8' to
a wildcard pattern, 2 available
07:39:24,425 DEBUG AbstractMatcher:68 - Value matches pattern
'edit/{id}'
07:39:24,428 DEBUG ParametersInterceptor:68 - Setting params
07:39:24,428 DEBUG DefaultWorkflowInterceptor:68 - Skipping
Interceptor... Method [getPersonById] found in exclude list.
07:39:24,429 DEBUG DefaultActionInvocation:68 - Executing action method
= getPersonById