本文整理汇总了Java中javax.faces.context.FacesContext.getCurrentInstance方法的典型用法代码示例。如果您正苦于以下问题:Java FacesContext.getCurrentInstance方法的具体用法?Java FacesContext.getCurrentInstance怎么用?Java FacesContext.getCurrentInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.faces.context.FacesContext
的用法示例。
在下文中一共展示了FacesContext.getCurrentInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: regContaBanco
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
public void regContaBanco(){
FacesContext facesContext = FacesContext.getCurrentInstance();
contaBanco.setIdtipoConta(Int(facesContext.getExternalContext().getRequestParameterMap().get("tipoconta")));
contaBanco.setIdtipoContaContabilistica(Int(facesContext.getExternalContext().getRequestParameterMap().get("contacontabalistica")));
contaBanco.setIdbanco(Int(facesContext.getExternalContext().getRequestParameterMap().get("banco")));
contaBanco.setIdTipoMoeda(Int(facesContext.getExternalContext().getRequestParameterMap().get("tipomoeda")));
contaBanco.setNumConta(facesContext.getExternalContext().getRequestParameterMap().get("numconta"));
String stra[] = new ContaBancoDao().regAccount(contaBanco);
if(stra != null && "true".equals(stra[0])){
RequestContext.getCurrentInstance().execute("limparCBForm()");
listContaBanco = new ContaBancoDao().getListContaBanco(null);
Validacao.atualizar("accountTableForm", "tableCantaBanco");
Message.addInfoMsg("Nova Conta Banco registada com sucesso!","changePassword", "growlChangePassword");
}else if(stra != null && "false".equals(stra[0]))
{ Message.addErrorMsg(stra[1],"changePassword", "growlChangePassword"); }
RequestContext.getCurrentInstance().execute("$('.modalProcess').hide()");
}
示例2: createResponse
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
private void createResponse(byte[] buf) throws IOException {
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) fc
.getExternalContext().getResponse();
String filename = generateFileName();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachement; filename=\""
+ filename + "\"");
response.setContentLength(buf.length);
OutputStream out;
out = response.getOutputStream();
out.write(buf);
out.flush();
out.close();
fc.responseComplete();
}
示例3: testBasic
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void testBasic()
{
TestNamingContainer a = new TestNamingContainer(); a.setId("a");
TestNamingContainer b = new TestNamingContainer(); b.setId("b");
TestNamingContainer d = new TestNamingContainer(); d.setId("d");
TestPanel e = new TestPanel(); e.setId("e");
TestPanel g = new TestPanel(); g.setId("g");
FacesContext context = FacesContext.getCurrentInstance();
context.getViewRoot().getChildren().add(a);
a.getChildren().add(b);
b.getChildren().add(d);
b.getChildren().add(g);
d.getChildren().add(e);
assertEquals("a:b:d:e", e.getClientId(context));
}
示例4: redirect
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
@Override
public void redirect(final String url) throws IOException
{
_checkResponse();
if (_servletResponse instanceof HttpServletResponse)
{
_httpServletResponse.sendRedirect(url);
FacesContext fc = FacesContext.getCurrentInstance();
if (fc != null)
{
fc.responseComplete();
}
}
else
{
throw new IllegalArgumentException(_LOG.getMessage(
"ONLY_HTTPSERVLETRESPONSE_SUPPORTED"));
}
}
示例5: getInstance
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
public Object getInstance() throws InstantiationException
{
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext == null)
{
log.error("Object " + getManagedBeanName() + " cannot be created since the faces context is null");
return null;
}
Application application = facesContext.getApplication();
Object resolvedObject = null;
if (isVBExpression(getManagedBeanName()))
{
ValueBinding vb = application.createValueBinding(getManagedBeanName());
if (vb != null)
{
resolvedObject = vb.getValue(facesContext);
}
}
else
{
VariableResolver resolver = application.getVariableResolver();
resolvedObject = resolver.resolveVariable(facesContext, getManagedBeanName());
}
return resolvedObject;
}
示例6: getViewMap
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Map<String, Object> getViewMap(boolean create)
{
// Note: replace this method body with a call to UIViewRoot.getViewMap(boolean) when
// Trinidad is upgraded to use JSF 2.0
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = facesContext.getViewRoot();
Map<String, Object> viewMap = null;
if (viewRoot != null)
{
Map<String, Object> attrs = viewRoot.getAttributes();
viewMap = (Map<String, Object>)attrs.get(_VIEW_MAP_KEY);
if (viewMap == null && create)
{
// Note, it is not valid to refer to the request context from outside of the request's
// thread. As such, synchronization and thread safety is not an issue here.
// This coincides with the JSF 2.0 code not using syncronization and using the non-thread
// safe HashMap.
viewMap = new HashMap<String, Object>();
attrs.put(_VIEW_MAP_KEY, viewMap);
}
}
return viewMap;
}
示例7: handleFileUpload
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
public void handleFileUpload(String imagem)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
try
{
// System.err.println(typeImagem(imagem));
byte[] bd = org.apache.poi.util.IOUtils.toByteArray(typeImagem(imagem).getInputStream());
ServletContext scontext = (ServletContext) facesContext.getExternalContext().getContext();
String arquivo = scontext.getRealPath("/Imagem/");
// System.err.println(arquivo);
File f = new File(arquivo);
for(File dd: f.listFiles())
if(dd.getName().contains(SessionUtil.getUserlogado().getNomeAcesso()+imagem))
dd.delete();
try (FileOutputStream fos = new FileOutputStream(arquivo+"/"+SessionUtil.getUserlogado().getNif()+imagem+ii+".jpg"))
{fos.write(bd);}
alterarImagem(imagem,"/Imagem/"+SessionUtil.getUserlogado().getNif()+imagem+ii+".jpg");
ii++;
RequestContext.getCurrentInstance().update("empresaReg:"+imagem);
}
catch (IOException ex)
{
Logger.getLogger(UtilizadorBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例8: _removeChild
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static void _removeChild(UIComponent uic, String removableChildId)
{
UIComponent removableChild = _findChildById(uic, removableChildId);
if (removableChild != null)
{
List<UIComponent> children = uic.getChildren();
children.remove(removableChild);
ComponentChange rca = new RemoveChildComponentChange(removableChildId);
FacesContext fc = FacesContext.getCurrentInstance();
ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
apm.addComponentChange(fc, uic, rca);
}
}
示例9: DialogRequest
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public DialogRequest(
UIViewRoot targetRoot,
String clientId,
String formId,
Map<String,Object> dialogProperties,
boolean usePopup
)
{
_clientId = clientId;
_formId = formId;
_usePopup = usePopup;
if (dialogProperties == null)
dialogProperties = Collections.emptyMap();
Object width = dialogProperties.get("width");
Object height = dialogProperties.get("height");
FacesContext context = FacesContext.getCurrentInstance();
String url;
if (usePopup)
{
url = context.getApplication().getViewHandler().getActionURL(context, targetRoot.getViewId());
}
else
{
url = FredJSP.getRedirectURL(context,
targetRoot,
CoreRenderer.toString(width),
CoreRenderer.toString(height));
}
PageFlowScopeProvider provider = RequestContext.getCurrentInstance().getPageFlowScopeProvider();
_url = context.getExternalContext().encodeActionURL(provider.encodeDialogPageFlowScopeURL(context, url));
_dialogProperties = dialogProperties;
}
示例10: login
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
/**
* Process login. Connect to server and move to folder display page.
*/
public String login()
{
try
{
// login to the IMAP server
Properties props = new Properties();
Session session = Session.getInstance(props, null);
Store store = session.getStore("imap");
store.connect(_server, _username, _password);
setStore(store);
setRootFolders(FolderData.toFolderData(this, store.getDefaultFolder().list()));
// TODO: Add logged in indicator to restrict access
_gotoFolder(null);
// Set up the user's preferences; in a real app, these would
// be persisted somewhere.
PreferencesData preferences = new PreferencesData();
setPreferences(preferences);
}
// catch all exceptions and report them as errors
catch (Exception e)
{
FacesMessage errorMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR,
e.getMessage(), null);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, errorMessage);
return null;
}
return "success";
}
示例11: resolveImagePathForName
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
@Override
public String resolveImagePathForName(String filename, FileTypeImageSize size)
{
if (FacesContext.getCurrentInstance() != null)
{
return FileTypeImageUtils.getFileTypeImage(FacesContext.getCurrentInstance(), filename, size);
}
else
{
return null;
}
}
示例12: getTokenToViewIdString
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
/**
* Generate a string showing the token and the view id we have saved for that token
*
* This method should only be called when debugTokenCache() is true
*/
public static String getTokenToViewIdString(String token)
{
if (!_DEBUG_TOKEN_CACHE)
throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
FacesContext context = FacesContext.getCurrentInstance();
return _getTokenToViewIdString( _getTokenToViewIdMap(context), token);
}
示例13: pesquisaCB
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
public void pesquisaCB(){
FacesContext facesContext = FacesContext.getCurrentInstance();
pesquisaConta = facesContext.getExternalContext().getRequestParameterMap().get("pesq");
listContaBanco = new ContaBancoDao().resultPesqu(pesquisaConta, false, null);
Validacao.atualizar("accountTableForm", "tableCantaBanco");
RequestContext.getCurrentInstance().execute("$('.modalProcess').hide()");
}
示例14: verifyViewLocale
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
/**
* Verifies that the view locale is equal to the user's locale
*
*/
public static void verifyViewLocale() {
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) fc
.getExternalContext().getRequest();
HttpSession session = request.getSession();
String localeString = null;
if (session != null) {
localeString = (String) session.getAttribute("loggedInUserLocale");
}
// if the view locale differs from the users locale change the view
// locale
Locale locale = fc.getViewRoot().getLocale();
if (localeString != null && !locale.toString().equals(localeString)) {
Iterator<Locale> it = fc.getApplication().getSupportedLocales();
while (it.hasNext()) {
locale = it.next();
if (locale.toString().equals(localeString)) {
fc.getViewRoot().setLocale(locale);
return;
}
}
// we use the default locale if the requested locale was not
// found
if (!fc.getViewRoot().getLocale()
.equals(fc.getApplication().getDefaultLocale())) {
fc.getViewRoot().setLocale(
fc.getApplication().getDefaultLocale());
}
}
}
示例15: init
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
@PostConstruct
public void init() {
context = FacesContext.getCurrentInstance();
/**
* FG Info Flash: We need flash to make the param survive one redirect request
* otherwise param will be null
**/
flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
//Get UserId of user, who owns session
Map<String, Object> session = context.getExternalContext().getSessionMap();
id = context.getExternalContext().getRequestParameterMap().get("userid");
flash.put("uid", id);
String userProfId = String.valueOf(context.getExternalContext().getFlash().get("uid"));
LOG.info("userProfId: " + userProfId);
if (session.size() != 0 && session.get("user") != null) {
userId = (int) session.get("user");
LOG.info("SESSIOn UID: " + userId);
} else {
try {
context.getExternalContext().redirect("/pse/login.xhtml");
} catch (IOException e) {
LOG.error("Can't redirect to /pse/login.xhtml");
}
}
requestedCommunityList = new ArrayList<>();
approvedCommunityList = new ArrayList<>();
requestedCommunityList = service.getPending();
LOG.info("Size of Requested Comm: " + requestedCommunityList.size());
approvedCommunityList = service.getApproved();
LOG.info("Size of Requested Comm: " + approvedCommunityList.size());
}