TILES: Converting registration page from struts example = nullpointer?

J

Jack

Hi all,

I've been working on converting the struts example app to tiles and have a
problem (I think with scopes) - I have moved the <html:form.... stuff into
a seperate tile, and call it from a main tile. Unfortuntely this has
broken it:

java.lang.NullPointerException
at org.apache.struts.tiles.xmlDefinition.FactorySet.getDefinition
(FactorySet.java:156)
at
org.apache.struts.tiles.definition.ComponentDefinitionsFactoryWrapper.getDe
finition(ComponentDefinitionsFactoryWrapper.java:124)
at
org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition
(TilesRequestProcessor.java:180)

I also get problems after I submit the login form (actual form displays
fine, but bombs after submit). Oddly enough the form bean seems to be
created fine, it's just something on the Tiles parse that's not right.

Any Ideas where to look?

Cheers
 
J

Jack

Can you post the the JSP for the main tile and the included one, and
tiles-defs.xml if you're using it. Looks like it just can't find one
of the tiles.

Hi Wendy,

I had a little success over the weekend with this, by replacing

<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
with
<servlet-class>org.apache.struts.tiles.ActionComponentServlet</servlet-
class>

So it looks like the default actionservlet doesnt want to play ball. I
seem to recall that the latter is not depreciated, so not entirely sure
what's ideal. Makes sense though as it was Actions that failed with
hindsight.

Thanks
J
 
W

Wendy S

Jack said:
I had a little success over the weekend with this, by replacing
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
with

What do you have in struts-config.xml? I have ActionServlet (the first line
above) in web.xml, then struts-config has the Tiles plugin set up:

<!-- ========== Tiles plug-in setting settings =================== -->
<!-- Here we specified the tiles plug-in.
This plug-in register appropriate Request Processor -->
<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"
/>

(and further down)

<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml" />
<set-property property="definitions-debug" value="2" />
<set-property property="definitions-parser-details" value="2" />
<set-property property="definitions-parser-validate" value="true" />
</plug-in>
 
J

Jack

What do you have in struts-config.xml? I have ActionServlet (the
first line above) in web.xml, then struts-config has the Tiles plugin
set up:

Hi Wendy,

I added the line:

<controller
processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

and all systems go, many thanks! :)

Perhaps you can help me with another issue which is when I have a user
access a restricted page I throw them to the login page, this isnt a
redirect as the url doesnt change. what I want the login page to do on
success is to pop them back to the calling page, but it doesnt seem to want
to play ball... if I add:

return (mapping.getInputForward());

it simply redirects back to the login page which is wrong. Obviously I
need this to be dynamic as

return (mapping.findForward("mainmenu"));

will always forward to the same place.

Thanks!
J
 
W

Wendy S

Jack said:
Perhaps you can help me with another issue which is when I have a user
access a restricted page I throw them to the login page, this isnt a
redirect as the url doesnt change. what I want the login page to do on
success is to pop them back to the calling page, but it doesnt seem to want
to play ball... if I add:
return (mapping.getInputForward());
it simply redirects back to the login page which is wrong. Obviously I
need this to be dynamic as
return (mapping.findForward("mainmenu"));
will always forward to the same place.

The easiest thing to do, although it doesn't feel very Struts-like, is to
put something in the session session.setAttribute("returnTo",
"editSomething.do"); Then use that something to construct an ActionForward:

Here's a snippet of code from my project:

String path = "/" + request.getAttribute( "returnTo" )
+ "?selectedId=" + selectedId
+ "&userAction=" + request.getAttribute( "userAction" )
+ "&returningFromResolution=true";

log.debug( "Returning a forward to " + path + " with
redirect=true");

return new ActionForward( path , true );

(The 'true' in the ActionForward constructor says to do a redirect, so you
get the ugly URL with the parameters showing, but it was necessary to get
the URL to change for another part of my project to work right. That might
not be the case for you, so try it without that parameter first.)
 
S

Sudsy

Jack wrote:
Perhaps you can help me with another issue which is when I have a user
access a restricted page I throw them to the login page, this isnt a
redirect as the url doesnt change. what I want the login page to do on
success is to pop them back to the calling page, but it doesnt seem to want
to play ball... if I add:

return (mapping.getInputForward());

it simply redirects back to the login page which is wrong. Obviously I
need this to be dynamic as

return (mapping.findForward("mainmenu"));

will always forward to the same place.

Thanks!
J

Save the result from getInputForward() in a hidden field during the
FIRST invocation of your login servlet. Waiting until the second
time through (after user hits the submit button) will indeed give
you the login page as the forwarding page.
 
J

Jack

Save the result from getInputForward() in a hidden field during the
FIRST invocation of your login servlet. Waiting until the second
time through (after user hits the submit button) will indeed give
you the login page as the forwarding page.

Makes perfect sense when you put it like that :) only problem I have with
that is because it's a DynaValidatorForm the Action wont be called until
submit, so I cant see how I could pass the referrer without doing as Wendy
suggests and pass it to the jsp in the querystring somehow, which is a
little nasty as it means my basic forwards need hacking to add
querystrings.


Flow currently is:
Restricted action --> login.jsp --> loginaction --> login.jsp

Thanks
J.
 
J

Jack

The easiest thing to do, although it doesn't feel very Struts-like, is
to put something in the session session.setAttribute("returnTo",
"editSomething.do"); Then use that something to construct an
ActionForward:

Hi Wendy,

Only reason for not doing it that way is that it's not multy-window safe.
Been experimenting and trying to get the referrer from the logon action
(forwarding direct to the logon action instead of the logon jsp now) and
that still doesnt work though.

Seems a bit daft that something so simple in theory is so hard in practice
:-/

Cheers
J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top