struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pirzada rashid <pirzada.ras...@gmail.com>
Subject person.getId() not set with url paramter using NamedVariablePatternMatcher
Date Mon, 15 Oct 2012 05:23:23 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message