I'm really new to Java and I have to create an applet for signing documents electronically. The applet will be called from an ASP.Net web page application.
Right now, I embed the applet in page as a <object id="EDOCApplet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> and send parameters to the applet like this:
<PARAM id="EdocPath" NAME="EdocPath" value="\\some\where\file.txt" />
In the applet, I can get the value using applet's built-in method getParameter("EdocPath");
What I need is the ability to pass the applet a list of several files and their "display names". For instance, it would be simple to write it down like an XML string:
<DocumentList>
<UnsignedDocument Path="\\some\wehere\file1.txt" Description="Whatever comes here" />
<UnsignedDocument Path="\\some\wehere\file2.txt" Description="Something else" />
...
However, as far as I see in HTML4.01 specification, the PARAM HTML element may not have content and it has no end-tag.
The choices I'm considering, are:
html-encode the xml structure and send it to applet in a single PARAM object
creating a list of PARAM objects and constructing their names like "File1", "Description1", "File2", "Description2", "File3"... then in Java applet create a while loop to read filenames while there is any.
However, none of the solutions seems to be elegant. The question is, what's the best practice in this case?
Pass them comma-separated:
<param id="files" name="files"
value="\\some\where\file.txt,\\some\where\file.txt" />
and then use String.split():
String[] fileNames = param.split(",");
In case of more complex structures you can use JSON to represent them.
You can also provide your applet with a public method:
initFile(String path, String description)
and call this method from javascript code (in which you can loop)
var applet = getElementByTageName(applet);
applet.initFile("yourPath","yourDescription");
Related
Can anyone help me to understand the usage of TypedProperty in websphere commerce?
ie,How to pass values from one jsp to other using TypedProperty without a command class.I would prefer to handle it in my client side itself without invoking Command class..can anyone help me to sort out it?
Typed property is usually used to pass values from controller commands to JSPs. If you just want to pass values from one JSP to another, create a form in your first JSP and submit it to the second.
If this is a form submit, set the values you need to pass in element. In the results jsp you can get those values using ${WCParam.xxx} .
FYI - To list out all the values in WCParam object try to print the below in JSP :
${WCParamValues}
We use typedProperty when we need to send anything from the command. For example, you give an order ID from the first JSP and want to get the final amount to be passed the result JSP. Here in the command we use the orderID from the request object -> Then we use the OrderAccessBean to get the OrderTotal -> then we set this to a TypedProperty object -> we then set this TypedProperty object to request properties using setRequestProperties() OOB method in a controller command.
Hope this makes it clear !
TypedProperty is a class in Java which can be compared to Hashmap in Java for better understanding. It is a name value pair combination.
I just wanted to understand the problem before answering further.
Why do you want to use TypedProperty in Jsp to pass the value from one jsp to another?
Are you importing the second jsp or including the second jsp to which you have to pass the values to?
If you are importing, you can use c:param tag to pass the values to the second jsp.
For included jsps, the values are already available in the second JSP.
Please include code snippets to explain your problem so that it can be answered clearly.
You can pass parameters from one jsp to another by using the following code snippet:
<c:import url="child.jsp">
<c:param name="name1" value="value1" />
<c:param name="name2" value="value2" />
<c:param name="name3" value="value3" />
</c:import>
Within the child.jsp you can read the parameters by using:
<c:out value="${param.name1}" />
<c:out value="${param.name2}" />
<c:out value="${param.name3}" />
A TypedProperty is nothing but a Wrapper to HashMap. So that's nothing to do here with passing values from one JSP to another JSP. Without invoking a command, you can't pass a Java object to another JSP.
And that is the very basic of Command Framework. I would prefer to go with the first answer.
I'm using the Stripes framework. I want to pass non-string Objects to an ActionBean. Is this possible?
I am trying to do:
<s:url var="statementUrl" beanclass="sempedia.action.StatementActionBean" prependContext="false" >
<s:param name="property" value="${row.key}" />
<s:param name="values" value="${row.value}" />
<s:param name="myString" value="Why kick a moo cow" />
</s:url>
<jsp:include page="${statementUrl}"/>
Where row.key resolvs to a custom class I have defined and row.value is an ArrayList of a custom class I have defined
Nope, nothing really.
I mean, there's always a way. You could serialize the forms out to a byte array and Base64 encode in to a string and then pass that as an argument.
But then you start running in to URL limits (they can only be so long).
If practical, you could save the data in the Session and simply refer to it later. You could use Stripes FlashScope, which stuffs it in the Session but only for the next request, then it goes away.
You could encode the data in to a HTML form, but then you would need to POST that rather than use a GET for it.
You could save the data out to another store (a database, memcache, something like that), and simply return a key to it, then pass in the key.
Really depends on the lifecycle of what you're trying to do, and the nature of the data.
Some background: I am building a custom JSF component. The component is basically a text editor and it should have a "Save" -button for saving the content string of the editor. As I am using the CodeMirror library, I need to fetch the content (string) from the editor with javascript and send that to the server. Therefore, in this case I cannot use XML-based JS invocation such as f:ajax.
The question: I was planning to send the string with jsf.ajax.request, but it doesn't directly support calling methods on beans. How can I invoke a method in a bean with JSF in AJAX manner?
There at least two ways to get around this:
Include a hidden form to page with hidden inputfield. Update that inputfield from javascript and then call jsf.ajax.request to post that form. Custom actions can be invoced in the property's getter or setter if needed.
Do the request with raw XMLHttpRequest (or maybe with help from some other JS library). Create a servlet and call that.
Both ways are clumsy and the latter also breaks out of JSF scope.
Am I missing something? How do you do these?
There is a quite similar question, but the answers given only refer to XML-based AJAX invocations. There is also another similar question, but that refers to XML-based AJAX calls as well.
I couldn't find out how to call beans direcly with javascript, but here is a hack around calling f:ajax-declaration from javascript:
1) Create a hidden form with fields for all the data that you want to send to the server. Include a h:commandButton as well:
<h:form id="hiddenForm" style="display: none;">
<h:inputHidden id="someData" value="#{someBean.someData}" />
<h:commandButton id="invisibleClickTarget">
<f:ajax execute="#form" listener="#{someBean.myCoolActionOnServer()}" />
</h:commandButton>
</h:form>
As usual, listener attribute, #{someBean.myCoolActionOnServer()} in this case, refers to the method that you want to execute on the server.
2) In some other button use onclick to call for your special javascript AND click the trigger-button via javascript:
<h:commandButton value="Click me" onclick="populateTheForm('hiddenForm'); document.getElementById('hiddenForm:invisibleClickTarget').click(); return false;" />
populateTheForm() should actually fill the data into hiddenForm's fields.
This is a simplification of my case but should work. Still looking for more conventient approach, though.
I did this task several times. Yo don't need multiply hidden fiels. You can use only one hidden field, convert all input values to JSON object via JSON.stringify and set into this field. On the server side - deserialize JSON object (there are many Java libs for that) to an Java class. That's all.
I am new to JSP and Servlets.
What i want to know is the best way to pass some customized message to client web pages.
For example suppose i have a web page say student.jsp which has a form,to register a new student to our online application.after successfully inserting all the fields of the form,
user submits the form and data is submitted to our servlet for further processing.Now,Servlet validates it and add it to our database.so,now servlet should send a message indicating a
successful insertion of data entered by end user to end user (In our case student.jsp).
So,i could i pass this type of message to any client web page.
I don't want to pass this message as URL query String.
is there ant other better and secure way to pass these type of messages ...
use request.setAttribute("message", yourMessage) and then forward (request.getRequestDispatcher("targetPage.jsp").forward()) to the result page.
Then you can read the message in the target page via JSTL (<c:out value="${message}" />) or via request.getAttribute(..) (this one is not preferable - scriptlets should be avoided in jsp)
If you really need response.sendRedirect(..), then you can place the message in the session, and remove it after it is retrieved. For that you might have a custom tag, so that your jsp code doesn't look too 'ugly'.
I think it looks like this in JSTL:
<c:remove var="message" scope="session" />
I also think that, if "message" is a Java String, it can be set to the empty string after it's been used like this:
<c:set var="message" scope="session" value="" />
Actually, it also looks like it works if "message" is an array of Java Strings: String[]...
Is there a cleaner way to do this in a JSP/Struts1 setup ?
... some HTML here ...
EDIT: In admin mode I would like to have access to additional parameters from a form element,
e.g. from the form element:
input type="text" value="Test user" name="Owner"
EDIT 2: Actually, my problem is very similar to the question that was asked in : Conditionally Render In JSP By User
But I don't really get the "pseudo-code" from the likely answer
Is SessionConfig exposed as a bean in your JSP (as part of request / session / Struts Form)?
If it's not, you can expose it. And if it's a static class containing global settings (which, by the looks of it, is a possibility), you can create a small wrapper and put it in the servlet context which you'd then be able to access from Struts tags as scope="application".
Once that's done you can check your condition via Struts tags:
<logic:equal name="sessionConfig" property="adminMode" value="true">
... your HTML here
</logic:equal>
Or, if you're using EL / JSTL, same can be done via <core:if>.
Without more information, it's hard to answer this, but I'd think instead of separate views: one for admin mode, one for normal mode. Extracting the parts of your pages into tiles will help you do this without a lot of pain; see: http://tiles.apache.org/