You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Oscar Picasso <os...@yahoo.com> on 2006/05/02 17:23:11 UTC

ASO and browser cookie disabled

Hi,

I have a login component that creates a session scoped ASO on the login form submission.

I works fine only if the client browser supports cookies. If not,no session is created and obviously the ASO is lost between requests.

I thought that in case the browser not supporting cookies a SESSION ID would be stored in the urls to keep track of the session.

Do I need to do something special to allow session creation even if cookies are not enabled on the client side ?

Oscar

		
---------------------------------
Love cheap thrills? Enjoy PC-to-Phone  calls to 30+ countries for just 2¢/min with Yahoo! Messenger with Voice.

PropertyselectionModel Q

Posted by Peter Verhoye <pe...@synergetic-solutions.be>.
Hi all,

I'm trying to do the following:

We have an object (Account) which contains an other object (Language).
To edit the account, I've created an accountEdit page where I want to
have a dropdown box that shows the list of languages one can set for an
account. But, I want the list to be set to the language the account
already has if available.
So, I've already created the following:

public class LanguageSelectionModel implements IPropertySelectionModel,
Serializable {
	private static final long serialVersionUID = -3912209045599735086L;

	private List<Language> languageList;

	private String languageId;

	public LanguageSelectionModel(List<Language> languageList, String
languageId) {
		this.languageList = languageList;
		this.languageId = languageId;
	}

	public int getOptionCount() {
		return languageList.size();
	}

	public Object getOption(int index) {
		return languageList.get(index);
	}

	public String getLabel(int index) {
		return languageList.get(index).getDescription(languageId);
	}

	public String getValue(int index) {
		return Integer.toString(index);
	}

	public Object translateValue(String value) {
		 return getOption(Integer.parseInt(value));
	}
}

In the AccountEdit.page file I have this:
<component id="language" type="PropertySelection">
	<binding name="model" value="availableLanguages"/>
	<binding name="value" value="account.language"/>
</component>


In the AccountEdit.java file I have the following:
public IPropertySelectionModel getAvailableLanguages() {
	String languageId =
getVisitObject().getContactPerson().getLanguage().getId();
	return new LanguageSelectionModel(getLanguageDAO().findLanguages(),
languageId);
}

Now, this all seems to work except that the combobox does not get
initialised on the correct Language object. Now, I think I know why but
I don't know how I should initialise the PropertySelectionModel.

Anyway has an idea or so?

Thank you!!

BB
Peter



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: List of logged users

Posted by Martijn Hinten <ma...@cumquat.nl>.
Implement a HttpSessionListener. This listener will be notified of all 
sessions that are destroyed (it's sessionDestroyed() method will be 
called). In that method you can check which user is logged off en remove 
that user from the (applicationscope, I guess) list.

See code sample below.

Good luck,
Martijn

An example of a session listener that just counts sessions:

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SessionWatcher implements HttpSessionListener {

private static final Log log = LogFactory.getLog(HttpSessionListener.class);

private static int activeSessions = 0;

/*
* @see 
javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
*/
public void sessionCreated(HttpSessionEvent event) {
activeSessions++;

log.debug("Session created with id:"+event.getSession().getId()
+". No of active sessions:"+activeSessions);
System.out.println("Session created with id:"+event.getSession().getId()
+". No of active sessions:"+activeSessions);


}


/*
* @see 
javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
*/
public void sessionDestroyed(HttpSessionEvent event) {
if(activeSessions > 0) {
activeSessions--;
}
log.debug("Session destroyed with id:"+event.getSession().getId()
+". No of active sessions:"+activeSessions);
System.out.println("Session destroyed with id:"+event.getSession().getId()
+". No of active sessions:"+activeSessions);

}


}


Add something like this to your web.xml:

<listener>
<listener-class>
com.zenz.mzz.view.listeners.SessionWatcher
</listener-class>
</listener>




Oscar Picasso wrote:

>Hi,
>
>I am looking for advises on how to implement a use case that is, think, quite common.
>
>In my application users can log in. They can also loggout either explicitly or because of session timeout.
>
>In one part of my application I want to display the total number of logged users and a list of each of these users.
>
>My main problem is how to remove an user from the list when he is logged out implicitly by a  session timeout.
>
>How would you solve this ?
>
>Thanks
>
>		
>---------------------------------
>How low will we go? Check out Yahoo! Messenger’s low  PC-to-Phone call rates.
>  
>

-- 


*Cumquat Information Technology*
De Dreef 19
3706 BR Zeist
T +31 (0)30 - 6940490
F +31 (0)10 - 6940499
http://www.cumquat.nl <http://www.cumquat.nl/>

martijn.hinten@cumquat.nl <ma...@cumquat.nl>
M +31 6 22 384 318


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: List of logged users

Posted by James Carman <ja...@carmanconsulting.com>.
You can use a session listener for this:

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSessionListener
.html

You register it in your web.xml file.  


-----Original Message-----
From: Oscar Picasso [mailto:oscgoogle@yahoo.com] 
Sent: Thursday, May 04, 2006 8:15 AM
To: Tapestry users
Subject: List of logged users

Hi,

I am looking for advises on how to implement a use case that is, think,
quite common.

In my application users can log in. They can also loggout either explicitly
or because of session timeout.

In one part of my application I want to display the total number of logged
users and a list of each of these users.

My main problem is how to remove an user from the list when he is logged out
implicitly by a  session timeout.

How would you solve this ?

Thanks

		
---------------------------------
How low will we go? Check out Yahoo! Messenger's low  PC-to-Phone call
rates.



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


List of logged users

Posted by Oscar Picasso <os...@yahoo.com>.
Hi,

I am looking for advises on how to implement a use case that is, think, quite common.

In my application users can log in. They can also loggout either explicitly or because of session timeout.

In one part of my application I want to display the total number of logged users and a list of each of these users.

My main problem is how to remove an user from the list when he is logged out implicitly by a  session timeout.

How would you solve this ?

Thanks

		
---------------------------------
How low will we go? Check out Yahoo! Messenger’s low  PC-to-Phone call rates.

Re: ASO and browser cookie disabled [SOLVED or BUG?]

Posted by Paul Cantrell <ca...@pobox.com>.
Cookies will, of course, manage the session if you bypass Tapestry  
completely and just do <a href=""> ... but it doesn't sound right  
that PageLink behaves that way inside a form.

If nobody comes up with a good answer on the list, I'd say file it in  
Jira.

On May 2, 2006, at 2:12 PM, Oscar Picasso wrote:

> There was a PageLink in the actual form component. If I move the  
> PageLink out of the form component the ;jsessionid=xxx is generated.
>
> The strange thing is that if the browser support cookies, the  
> session is correctly managed even if the form component contains a  
> PageLink.
>
> Isn't that a bug ? It is at least inconsistent.
>
> // The login form
> ...
>   <form jwcid="@Form" class="login" listener="listener:login">
>     <table>
>       <tr>
>         <td><label jwcid="@FieldLabel" field="component:username"/ 
> ></td>
>           <td><input jwcid="username@TextField"  
> value="ognl:username" displayName="votre pseudo"
> maxlength="15"/></td>
>       </tr>
>       <tr>
>         <td><label jwcid="@FieldLabel" field="component:password"/ 
> ></td>
>           <td>
>           <input jwcid="password@TextField" value="ognl:password"  
> displayName="mot de passe"
> maxlength="15" hidden="true"/>
>           <input type="submit" value="ok" class="ok"/>
>         </td>
>       </tr>
>     </table>
>     <a href="#" jwcid="@PageLink" page="pages/LostLogin"><small>mot  
> de passe ou pseudo oublié ?</small></a>
>     </form>
> ...
>
>
>
> 		
> ---------------------------------
> Blab-away for as little as 1¢/min. Make  PC-to-Phone Calls using  
> Yahoo! Messenger with Voice.

_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: ASO and browser cookie disabled [SOLVED or BUG?]

Posted by Oscar Picasso <os...@yahoo.com>.
There was a PageLink in the actual form component. If I move the PageLink out of the form component the ;jsessionid=xxx is generated.

The strange thing is that if the browser support cookies, the session is correctly managed even if the form component contains a PageLink.

Isn't that a bug ? It is at least inconsistent.

// The login form
...
  <form jwcid="@Form" class="login" listener="listener:login">
    <table>
      <tr>
        <td><label jwcid="@FieldLabel" field="component:username"/></td>
          <td><input jwcid="username@TextField" value="ognl:username" displayName="votre pseudo" 
maxlength="15"/></td>
      </tr>
      <tr>
        <td><label jwcid="@FieldLabel" field="component:password"/></td>
          <td>
          <input jwcid="password@TextField" value="ognl:password" displayName="mot de passe" 
maxlength="15" hidden="true"/>
          <input type="submit" value="ok" class="ok"/>
        </td>
      </tr>
    </table>
    <a href="#" jwcid="@PageLink" page="pages/LostLogin"><small>mot de passe ou pseudo oublié ?</small></a>
    </form>
...



		
---------------------------------
Blab-away for as little as 1¢/min. Make  PC-to-Phone Calls using Yahoo! Messenger with Voice.

Re: ASO and browser cookie disabled

Posted by Oscar Picasso <os...@yahoo.com>.
Paul Cantrell <ca...@pobox.com> wrote: Normally, Tapestry does handle this for you -- or rather, it passes  
the job along to the servlet container, which will usually append a  
";jsessionid=xxxx" to your requests.
That's what I expected.
However, if you're bypassing Tapestry to generate links directly --  
for example, by using a plain old  in your page, instead  
of one of the link components, or a  instead of a 
jwcid="@Form"> -- I doubt Tapestry will append the URL.
I am not bypassing Tapestry. I use XXXLink and form components and no ;jsessionid=xxx is appended to the requests.

It would be helpful if you could send a snippet of the page template  
for the form or link where the session is being lost.


Some of the relevant code.

// An exemple of a link in the page
<a href="#" jwcid="@PageLink" page="pages/Home">Home</a>


// The page class
public abstract class HubPage extends BasePage {
....
    @InjectState("user")
    public abstract UserState getUserState();
    public abstract void setUserState(UserState state);

    @InjectStateFlag("user")
    public abstract boolean getUserStateExists();
...
}

// The login component class
public abstract class Login extends BaseComponent {
    
    @InjectObject("service:hub.DaoManager")
    public abstract DaoManager getDaoManager();
    public abstract String getUsername();
    public abstract String getPassword();

    ...
    public void login()
    {
        final User user = getDaoManager().getUserDao().findByName(getUsername());
        final Encrypter encrypter = Encrypter.getEncrypter();
        if(encrypter.isValidPassword(getPassword(), user)
        {
            ((HubPage) getUserState()).setUser(user);
        }
    }

...
}

// The login form
...
  <form jwcid="@Form" class="login" listener="listener:login">
    <table>
      <tr>
        <td><label jwcid="@FieldLabel" field="component:username"/></td>
          <td><input jwcid="username@TextField" value="ognl:username" displayName="votre pseudo" maxlength="15"/></td>
      </tr>
      <tr>
        <td><label jwcid="@FieldLabel" field="component:password"/></td>
          <td>
          <input jwcid="password@TextField" value="ognl:password" displayName="mot de passe" maxlength="15" hidden="true"/>
          <input type="submit" value="ok" class="ok"/>
        </td>
      </tr>
    </table>
    </form>
...

// Hivemind 
  <!-- state objects -->
  <contribution configuration-id="tapestry.state.ApplicationObjects">
    <state-object name="application" scope="application">
      <create-instance class="hub.web.ApplicationState"/>
    </state-object>
    <state-object name="user" scope="session">
      <create-instance class="hub.web.UserState"/>
    </state-object>
  </contribution>



		
---------------------------------
Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.

Re: ASO and browser cookie disabled

Posted by Paul Cantrell <ca...@pobox.com>.
Normally, Tapestry does handle this for you -- or rather, it passes  
the job along to the servlet container, which will usually append a  
";jsessionid=xxxx" to your requests.

However, if you're bypassing Tapestry to generate links directly --  
for example, by using a plain old <a href=""> in your page, instead  
of one of the link components, or a <form> instead of a <form  
jwcid="@Form"> -- I doubt Tapestry will append the URL.

It would be helpful if you could send a snippet of the page template  
for the form or link where the session is being lost.

Cheers,

Paul


On May 2, 2006, at 10:23 AM, Oscar Picasso wrote:

> Hi,
>
> I have a login component that creates a session scoped ASO on the  
> login form submission.
>
> I works fine only if the client browser supports cookies. If not,no  
> session is created and obviously the ASO is lost between requests.
>
> I thought that in case the browser not supporting cookies a SESSION  
> ID would be stored in the urls to keep track of the session.
>
> Do I need to do something special to allow session creation even if  
> cookies are not enabled on the client side ?
>
> Oscar
>
> 		
> ---------------------------------
> Love cheap thrills? Enjoy PC-to-Phone  calls to 30+ countries for  
> just 2¢/min with Yahoo! Messenger with Voice.

_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org