本文整理汇总了Java中javax.portlet.PortletSession.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java PortletSession.setAttribute方法的具体用法?Java PortletSession.setAttribute怎么用?Java PortletSession.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.portlet.PortletSession
的用法示例。
在下文中一共展示了PortletSession.setAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAttribute
import javax.portlet.PortletSession; //导入方法依赖的package包/类
@Override
public void setAttribute(String name, Object value, int scope) {
if (scope == SCOPE_REQUEST) {
if (!isRequestActive()) {
throw new IllegalStateException(
"Cannot set request attribute - request is not active anymore!");
}
this.request.setAttribute(name, value);
}
else {
PortletSession session = getSession(true);
if (scope == SCOPE_GLOBAL_SESSION) {
session.setAttribute(name, value, PortletSession.APPLICATION_SCOPE);
this.globalSessionAttributesToUpdate.remove(name);
}
else {
session.setAttribute(name, value);
this.sessionAttributesToUpdate.remove(name);
}
}
}
示例2: serveResource
import javax.portlet.PortletSession; //导入方法依赖的package包/类
@Override
public void serveResource(ResourceRequest resourceRequest,
ResourceResponse resourceResponse) throws IOException,
PortletException {
System.out.println("=====serveResource=======");
String domainNo = ParamUtil.getString(resourceRequest, "domainNo");
String administrationNo = ParamUtil.getString(resourceRequest,
"administrationNo");
PrintWriter pw = resourceResponse.getWriter();
JSONObject juser = JSONFactoryUtil.createJSONObject();
juser.put("domainNo", domainNo);
juser.put("administrationNo", administrationNo);
pw.println(juser.toString());
PortletSession session = resourceRequest.getPortletSession();
// PortletMode portletMode= resourceRequest.getPortletMode();
// portletMode.s
session.setAttribute("domainNo", domainNo);
System.out.println(juser.toString());
}
示例3: serveResource
import javax.portlet.PortletSession; //导入方法依赖的package包/类
@Override
public void serveResource(ResourceRequest resourceRequest,
ResourceResponse resourceResponse) throws IOException,
PortletException {
System.out.println("=====serveResource=======");
String domainNo = ParamUtil.getString(resourceRequest, "domainNo");
String administrationNo = ParamUtil.getString(resourceRequest,
"administrationNo");
PrintWriter pw = resourceResponse.getWriter();
JSONObject juser = JSONFactoryUtil.createJSONObject();
juser.put("domainNo", domainNo);
juser.put("administrationNo", administrationNo);
pw.println(juser.toString());
PortletSession session = resourceRequest.getPortletSession();
session.setAttribute("domainNo", domainNo);
}
示例4: setErrorMessage
import javax.portlet.PortletSession; //导入方法依赖的package包/类
public static void setErrorMessage(PortletRequest request, String errorMsg, Throwable t)
{
if ( errorMsg == null ) errorMsg = "null";
PortletSession pSession = request.getPortletSession(true);
pSession.setAttribute("error.message",errorMsg);
OutputStream oStream = new ByteArrayOutputStream();
PrintStream pStream = new PrintStream(oStream);
log.error("{}", oStream);
log.error("{}", pStream);
// errorMsg = errorMsg .replaceAll("<","<").replaceAll(">",">");
StringBuffer errorOut = new StringBuffer();
errorOut.append("<p class=\"portlet-msg-error\">\n");
errorOut.append(FormattedText.escapeHtmlFormattedText(errorMsg));
errorOut.append("\n</p>\n<!-- Traceback for this error\n");
errorOut.append(oStream.toString());
errorOut.append("\n-->\n");
pSession.setAttribute("error.output",errorOut.toString());
Map map = request.getParameterMap();
pSession.setAttribute("error.map",map);
}
示例5: debugPrint
import javax.portlet.PortletSession; //导入方法依赖的package包/类
public static void debugPrint(PortletRequest request, String line)
{
if ( line == null ) return;
line = line.replaceAll("<","<").replaceAll(">",">");
PortletSession pSession = request.getPortletSession(true);
String debugOut = null;
try {
debugOut = (String) pSession.getAttribute("debug.print");
} catch (Throwable t) {
debugOut = null;
}
if ( debugOut == null ) {
debugOut = line;
} else {
debugOut = debugOut + "\n" + line;
}
pSession.setAttribute("debug.print",debugOut);
}
示例6: processActionReset
import javax.portlet.PortletSession; //导入方法依赖的package包/类
public void processActionReset(String action,ActionRequest request, ActionResponse response)
throws PortletException, IOException {
// TODO: Check Role
log.debug("Removing preferences....");
clearSession(request);
PortletSession pSession = request.getPortletSession(true);
PortletPreferences prefs = request.getPreferences();
try {
prefs.reset("sakai.descriptor");
for (String element : fieldList) {
prefs.reset("imsti."+element);
prefs.reset("sakai:imsti."+element);
}
log.debug("Preference removed");
} catch (ReadOnlyException e) {
setErrorMessage(request, rb.getString("error.modify.prefs")) ;
return;
}
prefs.store();
// Go back to the main edit page
pSession.setAttribute("sakai.view", "edit");
}
示例7: handleError
import javax.portlet.PortletSession; //导入方法依赖的package包/类
/**
* Handles errors that occur during a process action request
*/
private void handleError(ActionRequest request, ActionResponse response, Throwable error)
throws PortletException, IOException
{
// get the error bean from the session and set the error that occurred.
PortletSession session = request.getPortletSession();
ErrorBean errorBean = (ErrorBean)session.getAttribute(ErrorBean.ERROR_BEAN_NAME,
PortletSession.PORTLET_SCOPE);
if (errorBean == null)
{
errorBean = new ErrorBean();
session.setAttribute(ErrorBean.ERROR_BEAN_NAME, errorBean, PortletSession.PORTLET_SCOPE);
}
errorBean.setLastError(error);
response.setRenderParameter(ERROR_OCCURRED, "true");
}
示例8: checkRemoveAppScopedAttribute
import javax.portlet.PortletSession; //导入方法依赖的package包/类
protected TestResult checkRemoveAppScopedAttribute(PortletSession session) {
TestResult result = new TestResult();
result.setDescription("Remove an application scoped session attribute "
+ "and ensure it's null.");
result.setSpecPLT("15.3");
session.setAttribute(KEY, VALUE, PortletSession.APPLICATION_SCOPE);
session.removeAttribute(KEY, PortletSession.APPLICATION_SCOPE);
Object value = session.getAttribute(KEY, PortletSession.APPLICATION_SCOPE);
if (value == null) {
result.setReturnCode(TestResult.PASSED);
} else {
TestUtils.failOnAssertion("session attribute", value, null, result);
}
return result;
}
示例9: setAttribute
import javax.portlet.PortletSession; //导入方法依赖的package包/类
public void setAttribute(String name, Object value, int scope) {
if (scope == SCOPE_REQUEST) {
if (!isRequestActive()) {
throw new IllegalStateException(
"Cannot set request attribute - request is not active anymore!");
}
this.request.setAttribute(name, value);
}
else {
PortletSession session = getSession(true);
if (scope == SCOPE_GLOBAL_SESSION) {
session.setAttribute(name, value, PortletSession.APPLICATION_SCOPE);
this.globalSessionAttributesToUpdate.remove(name);
}
else {
session.setAttribute(name, value);
this.sessionAttributesToUpdate.remove(name);
}
}
}
示例10: testSimpleFormViewWithSessionAndBindOnNewForm
import javax.portlet.PortletSession; //导入方法依赖的package包/类
public void testSimpleFormViewWithSessionAndBindOnNewForm() throws Exception {
MockRenderRequest renderRequest = new MockRenderRequest();
MockRenderResponse renderResponse = new MockRenderResponse();
renderRequest.setParameter("action", "form-session-bind");
renderRequest.setParameter("age", "30");
TestBean testBean = new TestBean();
testBean.setAge(40);
SimplePortletApplicationContext ac =
(SimplePortletApplicationContext)simpleDispatcherPortlet.getPortletApplicationContext();
String formAttribute = ac.getFormSessionAttributeName();
PortletSession session = new MockPortletSession();
session.setAttribute(formAttribute, testBean);
renderRequest.setSession(session);
simpleDispatcherPortlet.doDispatch(renderRequest, renderResponse);
assertEquals("35", renderResponse.getContentAsString());
}
示例11: checkSetAttribute
import javax.portlet.PortletSession; //导入方法依赖的package包/类
protected TestResult checkSetAttribute(PortletSession session) {
TestResult res = new TestResult();
res.setName("Set Attribute Test");
res.setDescription("Sets and retrieves portlet sessionuest attribute.");
session.setAttribute(KEY, VAL);
Object val = session.getAttribute(KEY);
if(!VAL.equals(val)) {
res.setReturnCode(TestResult.FAILED);
res.setResultMessage("Retrieved value: '"+val+"' - Expected '"+VAL+"'");
}
else {
res.setReturnCode(TestResult.PASSED);
}
session.removeAttribute(KEY);
return res;
}
示例12: checkRemoveAttribute
import javax.portlet.PortletSession; //导入方法依赖的package包/类
protected TestResult checkRemoveAttribute(PortletSession session) {
TestResult res = new TestResult();
res.setName("Remove Session Attribute Test");
res.setDescription("Sets, removes and retrieves portlet request attribute.");
session.setAttribute(KEY, VAL);
session.removeAttribute(KEY);
Object val = session.getAttribute(KEY);
if(val!=null) {
res.setReturnCode(TestResult.FAILED);
res.setResultMessage("Retrieved value: '"+val+"' - Expected '"+VAL+"'");
}
else {
res.setReturnCode(TestResult.PASSED);
}
return res;
}
示例13: getParameterAndSaveItToSession
import javax.portlet.PortletSession; //导入方法依赖的package包/类
protected String getParameterAndSaveItToSession(String paramName, PortletRequest req, PortletSession session) {
String paramValue = req.getParameter(paramName);
if (paramValue != null) {
session.setAttribute(paramName, paramValue);
} else {
paramValue = (String) session.getAttribute(paramName);
}
return paramValue;
}
示例14: getFriendsCount
import javax.portlet.PortletSession; //导入方法依赖的package包/类
private int getFriendsCount(PortletSession session, FacebookClientWrapper facebookClient) throws PortletException,
IOException {
Integer friendsCount = (Integer) session.getAttribute(ATTR_FRIENDS_COUNT);
if (friendsCount == null) {
friendsCount = facebookClient.getFriendsCount();
session.setAttribute(ATTR_FRIENDS_COUNT, friendsCount);
}
return friendsCount;
}
示例15: getCurrentPageNumber
import javax.portlet.PortletSession; //导入方法依赖的package包/类
private int getCurrentPageNumber(RenderRequest request, PortletSession session) {
Integer currentPage;
if (request.getParameter(PARAM_PAGE) != null) {
currentPage = Integer.parseInt(request.getParameter(PARAM_PAGE));
session.setAttribute(PARAM_PAGE, currentPage);
} else {
currentPage = (Integer) session.getAttribute(PARAM_PAGE);
}
if (currentPage == null) {
currentPage = 1;
}
return currentPage;
}