You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Jacek Wiślicki <ja...@gmail.com> on 2006/09/06 19:31:19 UTC
Re: Problem showing portlet attributes and properties
Wiadomosc od Enrique Perez z 2006-09-06 18:30 brzmiala:
> Hi all,
>
> I was trying to see which attributes and properties my portlet views
> when clicking a button in a form.
> So I put this code in the "processAction(req,resp)" method:
> --------------------------------------------------------------------------------------
>
> private String atributos;
> private String propiedades;
>
> public void processAction (ActionRequest request, ActionResponse
> response)
> throws PortletException, IOException{
>
> String at1 =
> request.getAttributeNames().nextElement().toString();
> atributos = at1 + ": " +
> request.getAttribute(at1).toString()+"<br>";
> while (request.getAttributeNames().hasMoreElements()){
> String at =
> request.getAttributeNames().nextElement().toString();
> atributos = atributos + at + ": " +
> request.getAttribute(at).toString()+"<br>";
> }
>
> String prop1 =
> request.getPropertyNames().nextElement().toString();
> propiedades = prop1 + ": " +
> request.getProperty(prop1).toString()+"<br>";
> while (request.getPropertyNames().hasMoreElements()){
> String prop =
> request.getPropertyNames().nextElement().toString();
> propiedades = propiedades + prop + ": " +
> request.getProperty(prop).toString()+"<br>";
> }
> }
> --------------------------------------------------------------------------------------
>
> and show the result ("atributos" and "propiedades" strings) when
> rendering content in doView() method.
>
> But both loops seem to have no end =/
> I've tried just with two properties (or attributes); that is to say,
> removing the loops, and what I guess is that it's always picking the
> same property (or attribute).
>
> Is that something to do with my code? "nextElement()" is supposed to
> place the pointer in the next element of the Enumeration object, isn't it?
I've not tested your code, but the following will work:
Enumeration attrNames = request.getAttrubuteNames();
String attrs = "";
String attrName;
while(attrNames.hasMoreElements())
{
attrName = attrNames.nextElement().toString();
attrs += attrName + ": '" + request.getAttribute(attrName) + "' ";
}
--
pozdrawiam,
Jacek Wislicki
jacek.wislicki@gmail.com
http://www.nauka-biznes.org.pl/jetspeed/portal/
tel.: +48 502 408 444
gg: 2540358
skype: jacek_wislicki
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: Problem showing portlet attributes and properties
Posted by Jacek Wiślicki <ja...@gmail.com>.
Wiadomosc od Enrique Perez z 2006-09-11 18:41 brzmiala:
> It works fine. I didn't test it with request attributes, but with
> session attributes and it worked =)
> I think your code and mine look similar, but...
Your error was in continuous retrieving enumerations within loops. Each
call to request.getAttributeNames() (and similar ones) creates a new
enumeration whose iterator is at a 0 position. Therefore calling next()
method on such an object always returns true. You should create such an
enumeration object first, then iterate over it, subsequently calling
hasMoreElements() and next() methods.
--
pozdrawiam,
Jacek Wislicki
jacek.wislicki@gmail.com
http://www.nauka-biznes.org.pl/jetspeed/portal/
tel.: +48 502 408 444
gg: 2540358
skype: jacek_wislicki
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: Problem showing portlet attributes and properties
Posted by Enrique Perez <pe...@dit.upm.es>.
Thanks Jacek,
It works fine. I didn't test it with request attributes, but with
session attributes and it worked =)
I think your code and mine look similar, but...
Anyway, thanks for the help.
Regards,
Enrique
Jacek Wiślicki escribió:
> Wiadomosc od Enrique Perez z 2006-09-06 18:30 brzmiala:
>
>> Hi all,
>>
>> I was trying to see which attributes and properties my portlet views
>> when clicking a button in a form.
>> So I put this code in the "processAction(req,resp)" method:
>> --------------------------------------------------------------------------------------
>>
>> private String atributos;
>> private String propiedades;
>>
>> public void processAction (ActionRequest request, ActionResponse
>> response)
>> throws PortletException, IOException{
>>
>> String at1 =
>> request.getAttributeNames().nextElement().toString();
>> atributos = at1 + ": " +
>> request.getAttribute(at1).toString()+"<br>";
>> while (request.getAttributeNames().hasMoreElements()){
>> String at =
>> request.getAttributeNames().nextElement().toString();
>> atributos = atributos + at + ": " +
>> request.getAttribute(at).toString()+"<br>";
>> }
>>
>> String prop1 =
>> request.getPropertyNames().nextElement().toString();
>> propiedades = prop1 + ": " +
>> request.getProperty(prop1).toString()+"<br>";
>> while (request.getPropertyNames().hasMoreElements()){
>> String prop =
>> request.getPropertyNames().nextElement().toString();
>> propiedades = propiedades + prop + ": " +
>> request.getProperty(prop).toString()+"<br>";
>> }
>> }
>> --------------------------------------------------------------------------------------
>>
>> and show the result ("atributos" and "propiedades" strings) when
>> rendering content in doView() method.
>>
>> But both loops seem to have no end =/
>> I've tried just with two properties (or attributes); that is to say,
>> removing the loops, and what I guess is that it's always picking the
>> same property (or attribute).
>>
>> Is that something to do with my code? "nextElement()" is supposed to
>> place the pointer in the next element of the Enumeration object,
>> isn't it?
> I've not tested your code, but the following will work:
> Enumeration attrNames = request.getAttrubuteNames();
> String attrs = "";
> String attrName;
> while(attrNames.hasMoreElements())
> {
> attrName = attrNames.nextElement().toString();
> attrs += attrName + ": '" + request.getAttribute(attrName) + "' ";
> }
>
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org