The ID is sent to the service to let the service output pictures. Similar to JSP or ServelT. . I wrote a Photoservice in the Tapestry's AssetService.
Java code:
Package outsourcing.
Tapestry.
Utils;
Import Java.
IO.
IOEXCEPTION;
Import Javax.
servlet.
ServletContext;
Import Javax.
servlet.
ServletException;
Import org.
Apache.
Tapestry.
ApplicationRuntimeException;
Import org.
Apache.
Tapestry.
IComponent;
Import org.
Apache.
Tapestry.
IREQuestCYCLE;
Import org.
Apache.
Tapestry.
Tapestry;
Import org.
Apache.
Tapestry.
ENGINE.
AbstractService;
Import org.
Apache.
Tapestry.
ENGINE.
IengineServiceView;
Import org.
Apache.
Tapestry.
ENGINE.
Ilink;
Import org.
Apache.
Tapestry.
REQUEST.
ResponseoutputStream;
Import org.
Springframework.
CONTEXT.
ApplicationContext;
Import outsourcing.
DataBean.
AgentInformation;
Import outsourcing.
Facade.
OutsourcingFacade;
Import outsourcing.
Tapestry.
ENGINE
/ ** * @Author yin.deng * * Todo To change this generated type annotation template, go to the window - Preference - Java - Code style - Code Template * /
public
Class Photoservice
Extends AbstractService
{
public
Static
Final
String service_name = "photo";
Public ILINK GETLINK
(Irequestcycle Cycle, Icomponent Component,
Object
[
] Parameters
)
{
IF
Tapestry.
Size
(Parameters
)! =
1
)
Throw
New ApplicationRuntimeException
Tapestry.
Format
(
"Service-Single-Parameter", GetName
(
)
)
);
// service is stateless
Return CONSTRUCTLINK
(Cycle, GetName
(
),
Null, Parameters,
False
);
}
/ * * (Non-javadoc) * * @see org.apache.tapestry.Engine.abstractService # getName () * /
public
String getname
(
)
{
// TODO automatic generation method stub
Return service_name;
}
public
Void Service
(IEngineServiceView Engine, Irequestcycle Cycle, ResponseoutputStream Output
)
Throws servletexception,
IOEXCEPTION
{
Object
[
] Parameters = getParameters
(Cycle
);
IF
Tapestry.
Size
(Parameters
)! =
1
)
Throw
New ApplicationRuntimeException
Tapestry.
Format
(
"Service-Single-Parameter", GetName
(
)
)
);
String agentID =
(
String
) Parameters
[
0
];
ServletContext servletContext = cycle.
GetRequestContext
(
).
GetServlet
(
)
.
GetServletContext
(
);
WriteassetContent
(Engine, Cycle, Output, Agentid, ServletContext
);
}
/ ** @since 2.2 * * /
Private
Void WriteassetContent
IEngineServiceView Engine,
Irequestcycle Cycle, ResponseoutputStream Output,
String AgentID,
ServletContext ServletContext
)
{
// getting the content type and length is very dependant
// on support from the application server (represented
// Here by the servletcontext).
String contenttype = "image / jpeg";
AgentInformation Agentinformation = GetSourcingFacade
(Cycle
)
.
Findagentbyid
(
Long.
Valueof
(AgentID)
)
);
Output.
SetContentType
(ContentType)
);
// disable any further buffering inside the responseoutputstream
Try
{
Output.
Forceflush
(
);
Output.
Write
AgentInformation.
Getaitopo
(
)
);
}
Catch
(
IOEXCEPTION E
)
{
// TODO automatically generates a Catch block
e.
PrintStackTrace
(
);
}
}
Private OutsourcingFacade GetSourcingFacade
(Irequestcycle Cycle
)
{
ApplicationContext ApplicationContext = THIS
.
GetApplicationContext
(Cycle
);
Return
(OutsourcingFacade
ApplicationContext
.
GetBean
("OutsourcingFacade"
);
}
Public ApplicationContext GetApplicationContext
(Irequestcycle Cycle
)
{
Engine Engine = (Engine
CYCLE.
GetEngine
(
);
Return ENGINE.
GetApplicationContext
(
);
}
}
Then register to .application.
Java code:
XML Version = "
1.
0 "encoding =" UTF-
8 "?>
Public
"
// Apache Software Foundation // TapeStry Specification 3.0 // en "
"http:
//jakarta.apache.org/tapestry/dtd/tapestry_3_0.dtd ">
Engine- Class = "Outsourcing. Tapestry. ENGINE "> Value = "Outsourcing. Tapestry. Visit "/> Class = "Outsourcing. REPORT. ReportService "/> Class = "Outsourcing. Tapestry. Utils. Photoservice "/> application> Call in the Tapestry page Java code:
'OGNL: "/ GALILEO / APP? Service = photo & sp = S" item.aiid' width = " 600 "height =" 400 "/> You can expand your own yourself. .