I use JSPs, but I think the approach that I use will work for Velocity as
well.

Basically, what I do is add template selection logic to buildNormalContext.
In that method, I look at the current state of the portlet (more on that in
a sec) and then select the appropriate template.  For example, if the
portlet is in the "list" state, then I select the JSP template that displays
a list of elements (and expects certain things to be in the context).  If
the state is "detail", then I select the detail template and place the
appropriate information in the context.

There are two different ways to retain the state of the portlet: either in
the portlet temp space, or as a parameter on the url.  My first approach was
to store the state of the portlet in the temp space, but I discovered that
that led to confusing behavior, specifically when the user used the "back"
button on the browser.  I switched over to storing the state as a parameter
on the url as that led to a more straightforward user experience.

I set the state of the portlet through actions.  For example, I have a
"doDetail" method that adds the appropriate parameter to the request.  It
then calls buildNormalContext, which finds the flag and switches the
template appropriately.

This is a simplification, but you get the idea.

-- Michael


On 6/25/04 1:11 PM, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:

> Hi.. I'll try to explain my problem... hope you can undertand it.
> I've a VelocityPortlet with his default template. This template shows a
> list of articles already stored in the db, and has a link to add a new
> one: $jslink?eventSubmit_doEdit=
> 
> This method (doEdit) only set a template wich has the input fields:
>  
>     public void doEdit(RunData rundata, Context context) throws Exception
> {
>             String id = rundata.getParameters().getString(ID);
>             if (id!=null){
>                 ArticlesManager mng = new ArticlesManager();
>                 Article article = mng.getArticle(new
> Long(id).longValue());
>                 context.put("article", article);
>             }
>             context.put("totalLinks", new Integer(0));
>             setTemplate(rundata, "addArticle");
>     }
> 
> Until here, everything goes fine...
> 
> My problem is that I need to send some info from this template (addArticle
> - not the default) and come back to the same template, and always, despite
> of explicity set the template in the event method, the flow of the
> application goes to the default template.
> 
> This is the event I'm calling:
> 
>         public void doAddlinks(RunData rundata, Context context) throws
> Exception {
>                 ...
>             int totalLinks = rundata.getParameters().getInt("totalLinks",
> 0);
> 
>                 ...
> 
>             context.put("totalLinks", new Integer(totalLinks));
>             setTemplate(rundata, "addArticle");
>     }
> 
> please, any help would be very appreciated.
> 
> regards,
> Carlos.
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to