package org.japanosample.action;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.japano.action.ActionConfig;
import org.japano.Session;
import org.japanosample.SampleSession;
import org.japanosample.User;
import org.japano.metadata.annotation.*;
/**
Changes the data of the current user.
This is an example for a PingPongAction.
@author Sven Helmberger ( sven dot helmberger at gmx dot de )
@version $Id: ChangeUser.java,v 1.3 2005/02/25 01:27:14 fforw Exp $
*/
@JapanoAction ( library="/user", name="change" )
public class ChangeUser implements org.japano.action.PingPongAction
{
private SampleSession session;
private String newSystem;
/**
Field for adding a new operating system to the operating system list.
*/
@JapanoText ( maxLength=100 )
public void setNewSystem(String newSystem)
{
this.newSystem=newSystem;
}
/**
Returns the user to edit.
This is the bean accessor method for the nested User bean.
After the initialization of the action the bean is retrieved to populate
the bean form fields with the property values of the bean.
The action is kept in the user's session. If the action is performed the accessor method
is called again to set the properties of the bean to the updated values.
*/
@JapanoBean ( ignore={ "password", "passwordHash" } )
public User getUser()
{
return session.getUser();
}
/**
PingPongAction initialization method which provides
the action with the session it was created in.
*/
public void initialize(org.japano.Session session)
{
this.session=(SampleSession)session;
}
/**
Updates the logged in User with the form field values sent.
*/
public void perform(HttpServletRequest request, HttpServletResponse response) throws IOException
{
if (newSystem != null && newSystem.length() > 0)
{
User.addOperatingSystem( newSystem);
getUser().setOperatingSystem( newSystem);
}
session.setView("/editUser.jsp");
}
}