Bom dia pessoal, meu primeiro post aqui tenhu uma duvida que deve ser meio boba mas eu procurei muito ja tentei varias coisas e nada…bom meu problema eh o seguinte: eu tenho um aplicativo web que permite q abertura de um subform e neste subform eu tenho um botao(Done) que atraves de uma funcao javascript(Done()), consolida todos os meus inputs e selects em um xmlString(var xml)…porem eu necessito gravar essa variavel na session pois se eu fechar e re-abrir o subform os valores uma vez setados devem permanecer(enquanto na mesma session).
Ate porque o subform eh aberto como sendo um atributo de um outro form principal, entao esse atributo deve ser setado com minha xmlString processada na subform.
Meu codigo ta bem sujo pois ta tudo no mesmo lugar, html, javascript e java…mas espero que vo6 possam me ajudar.
<%@ page language="java" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.rmi.RemoteException" %>
<%@ page import="java.util.AbstractList" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.Enumeration" %>
<%@ page import="java.lang.String" %>
<%@ page import="java.lang.Object" %>
<%@ page import="javax.security.auth.Subject" %>
<%@ page import="javax.xml.parsers.ParserConfigurationException" %>
<%@ page import="org.xml.sax.SAXException" %>
<%@ page import="com.ibm.itim.apps.ApplicationException" %>
<%@ page import="com.ibm.itim.apps.identity.PersonMO" %>
<%@ page import="com.ibm.itim.apps.PlatformContext" %>
<%@ page import="com.ibm.itim.common.AttributeValue" %>
<%@ page import="com.ibm.itim.dataservices.model.DirectoryObject" %>
<%@ page import="com.ibm.itim.dataservices.model.ObjectProfile" %>
<%@ page import="com.ibm.itim.dataservices.model.DirectoryObjectEntity" %>
<%@ page import="com.ibm.itim.dataservices.model.DirectoryObjectSearch" %>
<%@ page import="com.ibm.itim.dataservices.model.DistinguishedName" %>
<%@ page import="com.ibm.itim.logging.SystemLog" %>
<%@ page import="com.ibm.itim.util.I18NMessage" %>
<%@ page import="com.ibm.itim.webclient.util.FormData" %>
<%@ page import="com.ibm.itim.webclient.util.ITIMPlatformContext" %>
<%@ page import="com.ibm.itim.webclient.util.LocaleUtil" %>
<%@ page import="com.ibm.itim.custom.AccessRights" %>
<%@ page import="com.ibm.itim.custom.AccessRight" %>
<%@ page import="br.com.companhiadesistemas.utils.LdapV3SearchTIM5" %>
<%@ page import="com.ibm.itim.dataservices.model.domain.AccountSearch" %>
<%@ page import="com.ibm.itim.dataservices.model.domain.AccountEntity" %>
<%@ page import="com.ibm.itim.dataservices.model.SearchParameters" %>
<%@ page import="com.ibm.itim.dataservices.model.domain.PersonSearch" %>
<%@ page import="com.ibm.itim.dataservices.model.domain.PersonEntity" %>
<%@ page import="com.ibm.itim.remoteservices.provider.SearchResult" %>
<%!
private String getAttributeName(HttpServletRequest request) {
String fieldName = request.getParameter("fieldname");
int lastDot = fieldName.lastIndexOf('.');
if (lastDot != -1)
return fieldName.substring(lastDot + 1);
else
return fieldName;
}
public String getAtributo(HttpServletRequest request){
String var = request.getParameter("Restricoes");
if (var==null)
return "nulo";
else
return var;
}
private String getAccessRights(
HttpServletRequest request,
HttpSession session)
throws ServletException, IOException {
try {
/*
* A user may open the subform, make changes, click 'done', and then reopen the subform.
* When this happens we want to use the changes that were saved in the session. This
* session attribute is deleted when the main form is redisplayed, so it won't be set if
* this is the first time the subform has been opened for this target object.
*/
AttributeValue av = (AttributeValue) session.getAttribute(FormData.SUB_FORM_ATTR_VALUE);
if (av == null) {
/*
* We need to read the attribute value from the target object.
*/
String personDN = request.getParameter("target_dn");
if (personDN == null || personDN.length() == 0)
/*
* The target_dn parameter will be null if this is a person create.
* Create an empty AccessRights object.
*/
return "personCreate";
/*
* Use the application API instead of dataservices. We want security
* enforced. NOTE: ITIMPlatformContext is not in the supported API.
*/
PlatformContext platform = ITIMPlatformContext.getInstance();
Subject subject = (Subject) session.getAttribute("subject");
PersonMO personMO =
new PersonMO(platform, subject, new DistinguishedName(personDN));
String attributeName = getAttributeName(request);
av = personMO.getData().getAttribute(attributeName);
if (av == null)
/*
* The person doesn't have any rights defined yet. Create an empty definition.
*/
return "noRightsDef";
else
/*
* Parse the XML rights definition.
*/
return av.toString() ;
} else
/*
* Parse the XML rights definition from the session.
*/
return av.toString();
} catch (ApplicationException e) {
throw new ServletException(e);
}
}
%>
<%
//DN==> ou=people(createAccount) or ou=accounts(modifyAccount)
//gets the DN from person or account
String DN = request.getParameter("target_dn");
//splits the DN to get the erglobalid
String erglobalid = DN.split(",")[0];
//splits the DN to get the type of DN, accounts/people
String objeto = DN.split(",")[2].split("=")[1];
//gets the Atribute Name witch started the subform
String attributeName = getAttributeName(request);
String acao="";
//initializates the 3 attributes needed
String segnfncorg = "";
String segnnome = "";
String segnfodesc = "";
AttributeValue attr = (AttributeValue) session.getAttribute(FormData.SUB_FORM_ATTR_VALUE);
//When Modifying an Account
//it's passed an account DN, so we'll "lookup" the AccountEntity by the DN
//and get the Atributes "segnnome" "segnfncorg" from the Entity
//and then use the "segnfncorg" to "fetch" the description of the
//"segnfncorg", witch is the respective "segnfodesc".
if(objeto.equals("accounts"))
{
AccountSearch search = new AccountSearch();
AccountEntity conta = search.lookup(new DistinguishedName(DN));
segnnome = segnnome + conta.getDirectoryObject().getAttribute("segnnome").getSingleValue().toString();
segnfncorg = segnfncorg + conta.getDirectoryObject().getAttribute("segnfncorg").getSingleValue().toString();
DirectoryObjectSearch doSearch = new DirectoryObjectSearch();
String filtro = "(segnfocod="+segnfncorg+")";
Collection desc = doSearch.fetch(new DistinguishedName("erglobalid=3725357112817454018,ou=services,erglobalid=00000000000000000000,ou=GPA,dc=tim"),filtro,new SearchParameters()).toCollection();
Object[] descrip = desc.toArray(new Object[0]);
if(descrip.length!=0)
{
DirectoryObjectEntity entidade = (DirectoryObjectEntity) descrip[0];
segnfodesc = "-"+entidade.getDirectoryObject().getAttribute("segnfodesc").getSingleValue().toString();
}
acao="Alterar a Conta";
}
//When Creating an Account
//it's passed a person DN, so we'll "lookup" the PersonEntity by the DN
//and get the Attribute "cn" from the Entity, as we do not have a value
//for "FuncaoOrganizacional" outside SegN, we'll just use the "CompleteName".
if(objeto.equals("people"))
{
PersonSearch search = new PersonSearch();
PersonEntity pessoa = (PersonEntity) search.lookup( new DistinguishedName(DN));
segnnome = segnnome + pessoa.getDirectoryObject().getAttribute("cn").getSingleValue().toString();
acao="Solicitar uma Conta";
}
String attrs = (String)request.getSession().getAttribute("resTypes");
request.setAttribute("segncod", request.getSession().getAttribute("resTypes"));
//boolean dontWait = false;
/**
String passou="";
String rights = null;
String attributeData = (String) request.getParameter("attributeData");
if (attributeData != null) {
/*
* We are here becuase the user clicked "Done" in the subform. This
* caused the user's modifications to be converted back into XML and
* submitted as the attributeData field in the attributeData form. We
* are now processing that submit.
*
* Don't parse the XML this time. Create an AttributeValue and save it
* in the session. Later we will generate a response page that simply
* closes the window.
*/
/** dontWait = true;
String attrName = getAttributeName(request);
AttributeValue attribute = new AttributeValue(attrName, attributeData);
session.setAttribute(FormData.SUB_FORM_ATTR_VALUE, attribute);
passou="NPassou";
} else {
/*
* This is the first pass. Get the parsed data.
*/
/** rights = getAccessRights(request, session);
passou = "passou";
}
**/
Enumeration param = request.getParameterNames();
while(param.hasMoreElements()){
out.println(param.nextElement());
}
%>
<%=session.getAttribute(FormData.SUB_FORM_ATTR_VALUE)%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<link href="/itim/console/ps/css/tungsten/skin.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="script_library.js"></script>
<script language="JavaScript" src="image_cache.js"></script>
<script language="JavaScript" src="help.js"></script>
<script type="text/javascript">
function addRight() {
if (window.opener && !window.opener.closed) {
var typeSelect = document.forms['body'].elements['resTypes'];
var restricao = typeSelect.options[typeSelect.selectedIndex].text;
document.forms['body'].elements['resTypes'].selectedIndex=0;
//alert(restricao);
var typeSelect5 = document.forms['body'].elements['Valor da Restricao'];
var valor = typeSelect5.value;
document.forms['body'].elements['Valor da Restricao'].value=null;
//alert(valor);
var typeSelect6 = document.forms['body'].elements['Todas'];
var todas = typeSelect6.checked;
document.forms['body'].elements['Todas'].checked=false;
//alert(todas);
var list = document.forms['body'].elements['Restricoes'];
//alert(list);
var i = list.length;
//alert(i);
if(todas)
valor="Todas";
while(valor==""){
alert('Preencha com um valor de Restricao');
return
}
var lista = '<%=segnnome%>'+"-"+restricao +"-"+valor;
//alert(lista);
list.options[list.length] = new Option(lista, i, true, true);
} else {
alert('Opening window has closed');
window.close();
}
}
function deleteRight() {
if (window.opener && !window.opener.closed) {
var list = document.forms['body'].elements['Restricoes'];
var index = Number(list.options[list.selectedIndex].value);
//alert(index);
list.options[list.selectedIndex] = null;
list.selectedIndex = -1;
//
// The values of the list's option objects are the indexes into the
// rights array of the corresponding AccessRight objects. Any options
// pointing at indexes higher than the one we just deleted need to be
// decremented by 1.
//
for (var i = 0; i < list.options.length; i++) {
var opt = list.options[i];
var j = Number(opt.value);
if (j > index) {
opt.value = j - 1;
}
}
} else
window.close();
}
function done() {
alert('<%=attributeName%>');
var rest = document.forms['body'].elements['Restricoes'];
var xml = ".~";
for(i=0;i<rest.length;i++){
//alert(rest.options[i].text);
xml=xml+rest.options[i].text+";";
//alert(xml);
}
xml=xml+"==";
xml=xml.replace(".~","<Restricao>");
xml=xml.replace(";==","</Restricao>");
var index = xml.search(";");
while(index!=-1){
xml=xml.replace(";","</Restricao><Restricao>");
index = xml.search(";");
}
alert(xml);
if (xml == "<Restricao>==" ){
alert('Adicione uma Restricao');
return
}
document.getElementsByName('attributeData')[0].value = xml;
document.forms['body'].submit();
alert(document.getElementsByName('attributeData')[0].value);
<%
//Map form = (Map) request.getAttribute("form");
String tente = (String) request.getSession().getAttribute("attributeData") ;
AttributeValue av1 = new AttributeValue("attributename", tente);
session = request.getSession(false);
session.setAttribute(FormData.SUB_FORM_ATTR_VALUE, av1);%>
alert(<%=tente%>);
window.close();
}
</script>
<title>Restricao de Usuario</title>
</head>
<body dir="ltr" style="background-color: rgb(255, 255, 255);">
<form id="body" method="POST" action="subformdetails.jsp">
<table style="text-align: left; width: 728px; height: 347px;" border="1" cellpadding="2" cellspacing="2">
<tr>
<td style="vertical-align: top; width: 17%; background-color: rgb(204, 204, 204);"><br></td>
<td style="vertical-align: top;">
<table style="text-align: left; width: 582px; height: 307px;" border="0" cellpadding="2"
cellspacing="0">
<tr>
<td style="vertical-align: top; color: rgb(80, 88, 120); font-weight: bold;
width: 66%;" rowspan="1" colspan="3">
<span class="cont1" id="W2782278210bdb8d131303ed0">
<span class="cont1" id="W5c4c5c4c10bdb8d1313b4708">
<span dir="ltr">
<span dir="ltr">
<span class="cont1" id="W140014010bdb8d1313ca2b0">
Gerenciar Usuarios > <%=acao%> > Restricoes >
Restricoes de Usuario
</span>
</span>
</span>
</span>
</span><br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">
<div style="position: absolute; left: 149px; top: 70px;">
<font size="2"><%=segnnome%><%=segnfodesc%></font><br>
</div>
</td>
<td style="vertical-align: top;">
<div style="position: absolute; left: 154px; top: 143px;">
<small>Tipo de Restricao</small><br>
<select name="resTypes" size="1" width="150" style="width: 150px;">
<option value="Basic">Basic</option>
<option value="Team Lead">Team Lead</option>
<option value="Help Desk">Help Desk</option>
<option value="Administrator">Administrator</option>
</select>
<br>
</div>
</td>
<td colspan="1" rowspan="8" style="vertical-align: top; width: 34%;">
<select style="width: 300px;" wrap="physical" readonly="readonly"
name="Restricoes" size="13" width="220" 1="">
</select>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><br></td>
<td style="vertical-align: top;"><br></td>
</tr>
<tr>
<td style="vertical-align: top;"><br></td>
<td style="vertical-align: top;"><br></td>
</tr>
<tr>
<td style="vertical-align: top;"><br></td>
<td style="vertical-align: top;"><br></td>
</tr>
<tr>
<td style="vertical-align: top;"><br></td>
<td style="vertical-align: top;"><br></td>
</tr>
<tr>
<td style="vertical-align: top;">
<div style="position: absolute; left: 153px; top: 226px;">
<small>Valor da Restricao</small><br>
<input name="Valor da Restricao" type="text"><br><br>
</div>
</td>
<td style="vertical-align: top;"><br></td>
</tr>
<tr>
<td style="vertical-align: top;"><br></td>
<td style="vertical-align: top;">
<div style="position: absolute; left: 339px; top: 244px;">
<input name="Todas" type="checkbox">
<small>Todas</small><br>
</div>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><br></td>
<td style="vertical-align: top;"><br></td>
</tr>
<tr>
<td style="vertical-align: top;"><br></td>
<td style="vertical-align: top;"><br>
<div style="position: absolute; left: 321px; top: 296px;"><br></div>
</td>
<td style="vertical-align: top;">
<input class="b1" dir="ltr" name="Add"
onclick="className='b1';this.blur();addRight();"
onmouseout="className='b1'" onmouseover="className='b2'" value="Add"
type="button">
<input class="b1" dir="ltr" name="Del"
onclick="className='b1';this.blur();deleteRight();"
onmouseout="className='b1'" onmouseover="className='b2'" value="Del"
type="button"><br>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" rowspan="1"
style="vertical-align: top; height: 10%; background-color: rgb(204, 204, 204);">
<div style="position: absolute; left: 299px; top: 330px;">
<input class="b1" dir="ltr" name="Done" onclick="className='b1';this.blur();done();"
onmouseout="className='b1'" onmouseover="className='b2'" value="Done"
type="submit">
<input class="b1" dir="ltr" name="Cancel" onclick="className='b1';this.blur();window.close();"
onmouseout="className='b1'" onmouseover="className='b2'" value="Cancel"
type="button"><br>
</div>
</td>
</tr>
</table>
<br>
<br>
<input name="fieldname" type="hidden" value="<%=request.getParameter("fieldname")%>">
<input name="attributeData" type="hidden">
</form>
</body>
</html>